This repository has been archived by the owner on Jul 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step01_preprocessing.m
114 lines (97 loc) · 3.8 KB
/
step01_preprocessing.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
clear all
clc
header_script
files=scandir(data_folder,'tif');
nFiles=length(files);
tif_in_sub_folder=0;
if nFiles==0
% In case we moved the raw files to a subfolder to allow those to be
% selectively unsynced
data_folder_new=fullfile(data_folder,'tif_files');
files=scandir(data_folder_new,'tif');
nFiles=length(files);
tif_in_sub_folder=1;
end
%%
for iFile=1:nFiles
file_name=fullfile(data_folder,files(iFile).name);
if exist(file_name,'file')==2
fprintf('Pre-processing file %s...\n',file_name)
save_name=fullfile(data_folder,'data_analysis',files(iFile).name);
save_name=strrep(save_name,'tif','mat');
if exist(save_name,'file')==0
%%% Create file based on class file
session_data=imaging_dataset(file_name);
session_data.save_data()
else
load(save_name,'session_data')
end
%%% Make sure filenames are relative to data folder on this machine
session_data.rebase(data_root)
%%% Extract info from movie
session_data.get_mov_info()
session_data.get_scim_data()
session_data.read_flyback()
%session_data.get_FOV_info(.85)
zoom_factor=session_data.mov_info.state.acq.zoomFactor;
% for zoom=2, the FOV size in micron is 500 by 680
% for session with other zoom, we scale linearly
session_data.get_FOV_info([500 680]./[191 512]*2/zoom_factor)
%%% Detect invalid frames
session_data.find_blank_frames() % due to laser power not being on
session_data.save_data()
if session_data.is_static_FOV()==0 % if recording at 1 position
fprintf('Session does not appear to be a static FOV...\n')
else
%%% Extract bitcode information from two sources
session_data.get_scim_bitCodes()
session_data.get_MWorks_bitCodes()
session_data.find_offset()
if ismac
fprintf('Offset was determined to be %d events...\n',session_data.bitCodes.offset)
end
%%% Save results so far
session_data.save_data()
%%% Motion Correction
use_GPU=1
if use_GPU==1&&gpuDeviceCount==1
session_data.set_smoothing_kernel_GPU()
%session_data.reset_reference_image();
session_data.find_reference_image_GPU()
else
session_data.set_smoothing_kernel()
%session_data.reset_reference_image();
session_data.find_reference_image()
end
if 0
%%
imshow(calc_gamma(session_data.motion_correction.reference_image.im,.5),[])
colormap(green)
end
%session_data.reset_motion_correction();
session_data.do_motion_correction()
session_data.find_motion_frames(2)
session_data.save_data()
if 0
%%
plot(session_data.motion_correction.shift_matrix(:,2))
hold on
bar(double(session_data.motion_correction.ignore_frames))
end
if 0
%%
session_data.visualize_motion_correction(1)
end
%%% Calculate z-projections
%session_data.reset_MIPs();
session_data.do_calc_MIPs()
if 0
%%
session_data.imshow(session_data.MIP_std.data)
end
session_data.save_data()
%session_data.do_motion_detection()
% plot(session_data.motion_proxy)
end
end
end