-
Notifications
You must be signed in to change notification settings - Fork 4
/
clusterStraightenStart.m
executable file
·96 lines (73 loc) · 3.11 KB
/
clusterStraightenStart.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function clusterStraightenStart(dataFolder)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creates Initial files for Straightening images
% Inputs:
% dataFolder- file path to data folder containing raw .dat file
% timing results, behavior folder, lowmag folder,
% alignments file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% write to status file
hostname = char( getHostName( java.net.InetAddress.getLocalHost ) );
if contains(hostname,'della')
Fid=fopen([dataFolder filesep 'status.txt'],'a');
status=[datestr(datetime('now')) ':Starting straightening \n'];
fprintf(Fid,status);
fclose(Fid);
end
%which volume to do for initial, not too close to begining because start
%might not have all video feeds tracking properly
counter=300;
%% bundle timing data
[bfAll,fluorAll,hiResData]=tripleFlashAlign(dataFolder);
vidInfo.bfAll=bfAll;
vidInfo.fluorAll=fluorAll;
vidInfo.hiResData=hiResData;
%% make time alignments
bf_ft=bfAll.frameTime;
fluor_ft=fluorAll.frameTime;
hi_ft=hiResData.frameTime;
bfIdxList=1:length(bfAll.frameTime);
fluorIdxList=1:length(fluor_ft);
bfIdxLookup=interp1(bf_ft,bfIdxList,hi_ft,'linear','extrap');
fluorIdxLookup=interp1(fluor_ft,fluorIdxList,hi_ft,'linear','extrap');
stack2BFidx=bfIdxLookup(diff(hiResData.stackIdx)==1);
stack2fluoridx=fluorIdxLookup(diff(hiResData.stackIdx)==1);
topLimit=min(max(hiResData.stackIdx),length(stack2BFidx));
BF2stackIdx=interp1(stack2BFidx,1:topLimit,bfIdxList,'nearest');
fluor2stackIdx=interp1(stack2fluoridx,1:topLimit,fluorIdxList,'nearest');
%% just using 300th volume for now
test_frame=counter;
%% load alignment data
%try to load the alignment file in the folder, otherwise, select them
%individual in the registration folder
alignments=load([dataFolder filesep 'alignments']);
alignments=alignments.alignments;
% deal with missing backgrounds
if ~isfield(alignments,'background');
alignments.background=0;
save([dataFolder filesep 'alignments'],'alignments');
end
%% calculate offset between frame position and zposition
zWave=hiResData.Z;
zWave=gradient(zWave);
zWave=smooth(zWave,100);
image_std=hiResData.imSTD;
image_std=image_std-mean(image_std);
image_std(image_std>100)=0;
[ZSTDcorrplot,lags]=crosscorr(abs(zWave),image_std,30);
ZSTDcorrplot=smooth(ZSTDcorrplot,3);
zOffset=lags(ZSTDcorrplot==max(ZSTDcorrplot));
%% Create straightened destination folder
destination= ['CLstraight_' datestr(now,'yyyymmdd')];
imageFolder2=[dataFolder filesep destination];
mkdir(imageFolder2);
%% do a sample image in range, for observation and for reference
tic
%Run straighten and segmentation on one volume
[~,~,Vtemplate,side,~,~]=WormCLStraighten_11(...
dataFolder,destination,vidInfo,alignments,[],zOffset,test_frame,'left',0);
%we need these of the outputs to save for the cluster straightening
display(['Finished image ' num2str(test_frame,'%3.5d') ' in ' num2str(toc) 's'])
%save initial workspace from first sample for later use
save([dataFolder filesep 'startWorkspace'],...
'destination', 'Vtemplate', 'zOffset', 'side','vidInfo')