Commit d0feeb59 authored by p.jhagema's avatar p.jhagema
Browse files

option to choose data type when saving tiffs

parent d23225c1
Pipeline #265427 passed with stage
in 48 seconds
function imwrite_tiff(data,filename) function imwrite_tiff(data,filename, dataType)
%IMWRITE_TIFF saves given data as \*.tif. %IMWRITE_TIFF saves given data as \*.tif.
% %
% ``imwrite_tiff(data,filename)`` % ``imwrite_tiff(data,filename)``
...@@ -39,6 +39,9 @@ function imwrite_tiff(data,filename) ...@@ -39,6 +39,9 @@ function imwrite_tiff(data,filename)
if ~endsWith(filename,'.tif','IgnoreCase',true) && ~endsWith(filename,'.tiff','IgnoreCase',true) if ~endsWith(filename,'.tif','IgnoreCase',true) && ~endsWith(filename,'.tiff','IgnoreCase',true)
filename = [filename , '.tif']; filename = [filename , '.tif'];
end end
if nargin < 3
dataType = 'single';
end
ttag.ImageLength = size(data,1); ttag.ImageLength = size(data,1);
ttag.ImageWidth = size(data,2); ttag.ImageWidth = size(data,2);
...@@ -46,12 +49,19 @@ ttag.Photometric = Tiff.Photometric.MinIsBlack; ...@@ -46,12 +49,19 @@ ttag.Photometric = Tiff.Photometric.MinIsBlack;
ttag.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; ttag.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
ttag.BitsPerSample = 32; ttag.BitsPerSample = 32;
ttag.SamplesPerPixel = 1; ttag.SamplesPerPixel = 1;
ttag.SampleFormat = Tiff.SampleFormat.IEEEFP;
switch dataType
case 'single'
ttag.SampleFormat = Tiff.SampleFormat.IEEEFP;
case 'uint32'
ttag.SampleFormat = Tiff.SampleFormat.UInt;
end
ttag.Software = 'MATLAB'; ttag.Software = 'MATLAB';
t = Tiff(filename,'w'); t = Tiff(filename,'w');
t.setTag(ttag); t.setTag(ttag);
t.write(single(data)); t.write(cast(data, dataType));
t.close(); t.close();
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment