-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwriteTIFF.m
More file actions
40 lines (34 loc) · 1.18 KB
/
writeTIFF.m
File metadata and controls
40 lines (34 loc) · 1.18 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
function writeTIF(data, tiffname,res)
if nargin < 3
res = [1 1]; % save generic resolution if none provided
end
%% save to tiff while keeping floating value
% writes data as a multi-channel TIFF with single prec. float pixels
filename = [tiffname '.tif'];
maxCount = 10;
count = 1;
while exist(filename, 'file') == 2
filename = [tiffname '_' num2str(count) '.tif'];
count = count +1;
if count == maxCount
break;
end
end
for k = 1:size(data,3)
t = Tiff(filename, 'a');
tagstruct.ImageLength = size(data, 1);
tagstruct.ImageWidth = size(data, 2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.XResolution = res(1);
tagstruct.YResolution = res(2); % YResolution encode z-res
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Photometric = 1;
tagstruct.BitsPerSample = 32; % float data
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
t.setTag(tagstruct);
t.write(single(data(:,:,k)));
t.close();
pause(0.01)
end
end