Skip to content

Commit 1671c02

Browse files
committed
update read_file
1 parent fa3aa33 commit 1671c02

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

read_file.m

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
[~,~,ext] = fileparts(path_to_file);
2121

22-
if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif');
22+
if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf');
2323
imData = loadtiff(path_to_file,sframe,num2read);
24+
%imData = bigread2(path_to_file,sframe,num2read);
2425
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5');
2526
% info = hdf5info(path_to_file);
2627
% dims = info.GroupHierarchy.Datasets.Dims;
@@ -36,20 +37,28 @@
3637
imData = h5read(path_to_file,['/',name],[ones(1,length(dims)-1),sframe],[dims(1:end-1),num2read]);
3738
elseif strcmpi(ext,'.avi')
3839
v = VideoReader(path_to_file);
39-
if nargin < 3
40-
num2read = v.Duration*v.FrameRate-sframe+1;
41-
end
42-
Y1 = readFrame(v);
43-
imData = zeros(v.Height,v.Width,num2read,'like',Y1);
44-
i = 0;
45-
while hasFrame(v)
46-
video = readFrame(v);
47-
i = i + 1;
48-
if i >= sframe
49-
imData(:,:,i-sframe+1) = video;
40+
if v.Duration*v.FrameRate < sframe
41+
imData = [];
42+
else
43+
if nargin < 3
44+
num2read = v.Duration*v.FrameRate-sframe+1;
45+
end
46+
num2read = min(num2read,v.Duration*v.FrameRate-sframe+1);
47+
Y1 = readFrame(v);
48+
imData = zeros(v.Height,v.Width,num2read,'like',Y1);
49+
i = 1;
50+
if sframe == 1
51+
imData(:,:,i-sframe+1) = Y1;
5052
end
51-
if i - sframe + 1 >= num2read
52-
break;
53+
while hasFrame(v) && (i - sframe + 1 < num2read)
54+
video = readFrame(v);
55+
i = i + 1;
56+
if i >= sframe
57+
imData(:,:,i-sframe+1) = video;
58+
end
59+
if i - sframe + 1 >= num2read
60+
break;
61+
end
5362
end
5463
end
5564
elseif strcmpi(ext,'.raw')

run_pipeline.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
% register files one by one. use template obtained from file n to
1414
% initialize template of file n + 1;
1515

16-
motion_correct = true; % perform motion correction
16+
motion_correct = true; % perform motion correction
1717
non_rigid = true; % flag for non-rigid motion correction
1818
if non_rigid; append = '_nr'; else; append = '_rig'; end % use this to save motion corrected files
1919
options_mc = NoRMCorreSetParms('d1',FOV(1),'d2',FOV(2),'grid_size',[128,128],'init_batch',200,...
20-
'overlap_pre',64,'mot_uf',4,'bin_width',200,'max_shift',24,'max_dev',8,'us_fac',50,...
20+
'overlap_pre',32,'mot_uf',4,'bin_width',200,'max_shift',24,'max_dev',8,'us_fac',50,...
2121
'output_type','h5');
2222

2323
template = [];
2424
col_shift = [];
2525
for i = 1:numFiles
2626
fullname = files(i).name;
27-
[folder_name,file_name,ext] = fileparts(fullname);
27+
[folder_name,file_name,ext] = fileparts(fullname);
2828
options_mc.h5_filename = fullfile(folder_name,[file_name,append,'.h5']);
29-
if motion_correct
29+
if motion_correct
3030
[M,shifts,template,options_mc,col_shift] = normcorre_batch(fullname,options_mc,template);
3131
save(fullfile(folder_name,[file_name,'_shifts',append,'.mat']),'shifts','-v7.3'); % save shifts of each file at the respective folder
3232
else % if files are already motion corrected convert them to h5
@@ -101,15 +101,15 @@
101101
'deconv_method','constrained_foopsi',... % neural activity deconvolution method
102102
'p',p,... % order of calcium dynamics
103103
'ssub',2,... % spatial downsampling when processing
104-
'tsub',4,... % further temporal downsampling when processing
104+
'tsub',2,... % further temporal downsampling when processing
105105
'merge_thr',merge_thr,... % merging threshold
106106
'gSig',tau,...
107107
'max_size_thr',300,'min_size_thr',10,... % max/min acceptable size for each component
108108
'spatial_method','regularized',... % method for updating spatial components
109109
'df_prctile',50,... % take the median of background fluorescence to compute baseline fluorescence
110110
'fr',fr/tsub,... % downsamples
111-
'space_thresh',0.5,... % space correlation acceptance threshold
112-
'min_SNR',3.0,... % trace SNR acceptance threshold
111+
'space_thresh',0.35,... % space correlation acceptance threshold
112+
'min_SNR',2.0,... % trace SNR acceptance threshold
113113
'cnn_thr',0.2,... % cnn classifier acceptance threshold
114114
'nb',1,... % number of background components per patch
115115
'gnb',3,... % number of global background components
@@ -118,16 +118,16 @@
118118

119119
%% Run on patches (the main work is done here)
120120

121-
[A,b,C,f,S,P,RESULTS,YrA] = run_CNMF_patches(data,K,patches,tau,0,options); % do not perform deconvolution here since
122-
% we are operating on downsampled data
121+
[A,b,C,f,S,P,RESULTS,YrA] = run_CNMF_patches(data.Y,K,patches,tau,0,options); % do not perform deconvolution here since
122+
% we are operating on downsampled data
123123
%% compute correlation image on a small sample of the data (optional - for visualization purposes)
124124
Cn = correlation_image_max(data,8);
125125

126126
%% classify components
127127

128128
rval_space = classify_comp_corr(data,A,C,b,f,options);
129129
ind_corr = rval_space > options.space_thresh; % components that pass the correlation test
130-
% this test will keep processes
130+
% this test will keep processes
131131

132132
%% further classification with cnn_classifier
133133
try % matlab 2017b or later is needed

0 commit comments

Comments
 (0)