-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstack_tiffs.m
More file actions
75 lines (68 loc) · 2.36 KB
/
stack_tiffs.m
File metadata and controls
75 lines (68 loc) · 2.36 KB
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
function stack_tiffs(directoryname,stack_name)
%% stack_tiffs
% written BPI 10/20/16
% is a quick function that will convert a folder of individual tiff images
% into a tiffstack.
%
% directoryname is the name of the directory holding the tiff images.
%
% stack_name is the name of the tiff stack that will be saved. If no input
% is given the default is directorynamestack.tif and it will be saved in
% the directory containing the directoryname. This is also the save
% directory if no directory is specified in stack_name.
%
% This program is very simple, so use it cautiously. It assumes that the ls
% command lists the files in the correct order. It takes all of the tiffs
% in a folder and saves them as a tiff stack.
%
%%%% Dependencies %%%%
% TIFFStack
% saveastiffs
% Copyright (C) 2017 Benjamin P Isaacoff
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%%
%move to directory with the imagess
curdir=pwd;
cd(directoryname);
%setting up the save filename
if nargin<2
save_name=[directoryname,'stack.tif'];
else
[save_directory,snam,~]=fileparts(stack_name);
if isempty(save_directory)
cd ..
save_directory=pwd;
cd(directoryname);
end
save_name=[save_directory,filesep,snam,'.tif'];
end
%listing all of the tif images
fnames=cellstr(ls('*.tif'));
%the first frame just to get the size
frame=TIFFStack(fnames{1});
%initializing the movie
mov=zeros([size(frame,1),size(frame,2),length(fnames)]);
%loop through each frame and save it to mov
for ii=1:length(fnames)
frame=TIFFStack(fnames{ii});
mov(:,:,ii)=frame(:,:);
end
%save it
options.overwrite=true;
saveastiff(uint16(mov),save_name,options);
%return to original directory
cd(curdir);
end