-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimresizeTIFFStack.m
More file actions
61 lines (59 loc) · 2.6 KB
/
Copy pathimresizeTIFFStack.m
File metadata and controls
61 lines (59 loc) · 2.6 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
% imresizeTIFFStack(InputPath, Scale, Method)
% Resize TIFF stack(s) into new file(s) with added filename prefix
% 'Resized_', using the MATLAB *imresize* function.
% If 'InputPath' is empty, this function will be applied to all TIFF files
% in the current directory. If 'Method' is not applied or empty, 'bicubic'
% will be used. 'Scale' is the output size (1-D) / the input size (1-D).
function imresizeTIFFStack(InputPath, Scale, Method)
if ~exist('Method', 'var') || isempty(Method)
Method = 'bicubic'; % default 'Method'
end
if ~isempty(InputPath)
if ~ischar(InputPath)
error('''InputPath'' has to be a string.');
end
[Directory, Filename, Extension] = fileparts(InputPath);
if isempty(Directory)
OutputPath = strcat('Resized_', Filename, Extension);
else
OutputPath = strcat(Directory, filesep, 'Resized_', ...
Filename, Extension);
end
Info = imfinfo(InputPath);
TotalFrameNumber = numel(Info);
for i = 1 : TotalFrameNumber
I = imread(InputPath, i, 'info', Info);
imwrite(imresize(I, Scale, Method), OutputPath, ...
'WriteMode', 'append', 'Compression', 'none');
end
else % 'InputPath' is empty
TifList = ls('*.tif*');
if ispc
TotalTifFileNumber = size(TifList, 1);
for j = 1 : TotalTifFileNumber
Info = imfinfo(TifList(j, :));
TotalFrameNumber = numel(Info);
OutputPath = strcat('Resized_', TifList(j, :));
for i = 1 : TotalFrameNumber
I = imread(TifList(j, :), i, 'info', Info);
imwrite(imresize(I, Scale, Method), OutputPath, ...
'WriteMode', 'append', 'Compression', 'none');
end
end
else % not running on a PC
TifList = strsplit(TifList);
TifList = TifList(~cellfun(@isempty, TifList));
TotalTifFileNumber = length(TifList);
for j = 1 : TotalTifFileNumber
Info = imfinfo(TifList{j});
TotalFrameNumber = numel(Info);
OutputPath = strcat('Resized_', TifList{j});
for i = 1 : TotalFrameNumber
I = imread(TifList{j}, i, 'info', Info);
imwrite(imresize(I, Scale, Method), OutputPath, ...
'WriteMode', 'append', 'Compression', 'none');
end
end
end
end
end