-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_template_from_file.m
44 lines (39 loc) · 1.16 KB
/
make_template_from_file.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
function [template,selected] = make_template_from_file(fn, ch, threshold,to_save)
if(nargin<1)
fn = [];
end
if(nargin<2)
ch = -1;
end
if(nargin<3)
threshold = [];
end
if(nargin<4)
to_save = true;
end
if(isempty(fn))
[filename, pathname] = uigetfile('*.tif','Select a file to open');
if(isequal(0,filename) || isequal(0,pathname))
template = [];
return
else
fn = fullfile(pathname,filename);
end
end
[pathstr,filename,~] = fileparts(fn);
dirname = fullfile(pathstr,'template');
if(~java.io.File(dirname).isDirectory())
mkdir(dirname);
end
fn_template_tif = fullfile(dirname,[filename '_avg.tif']);
fn_template_mat = fullfile(dirname,[filename '_avg.mat']);
[stack,info] = read_tiff(fn,ch);
selected = cell(size(stack,4),1);
for i = 1:size(stack,4)
[template(:,:,i),selected{i}] = make_template(stack(:,:,:,i),[],[],threshold);
end
if(to_save)
write_tiff(fn_template_tif,template,info);
save(fn_template_mat,'template','selected','fn');
end
end