-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwriteRGBTIFF.m
39 lines (34 loc) · 1.19 KB
/
writeRGBTIFF.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
% write uint8 RGB TIF stack
function writeRGBTIFF(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,4)
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.uint8;
tagstruct.Photometric = 1;
tagstruct.BitsPerSample = 8; % float data
tagstruct.SamplesPerPixel = 3;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
t.setTag(tagstruct);
t.write(uint8(data(:,:,:,k)));
t.close();
end
end