Multipage Tiff write in MATLAB doesn't work

﹥>﹥吖頭↗ 提交于 2020-01-16 18:46:34

问题


I'm reading in a Tiff using the below function, which works fine, but when I try to use my write function to write that same Tiff back to a different file, it's all 255's. Does anyone know how to fix this? Thanks, Alex.

function Y = tiff_read(name)
% tiff reader that works

info = imfinfo(name);
T = numel(info);

d1 = info(1).Height;
d2 = info(1).Width;

Y = zeros(d1,d2,T);
for t = 1:T
    temp = imread(name, t, 'Info',info);
    Y(:,:,t) = temp(1:end,1:end);
end

% Tiff writer that doesn't work
function tiff_write(Y,name)
% Y should be 3D, name should end in .tif
T = size(Y,3);
imwrite(Y(:,:,1),name);
for t = 2:T
    imwrite(Y(:,:,t),name,'WriteMode','append');
end

回答1:


Try using this line :

Y = zeros(d1,d2,T,'uint16');

instead of this one:

Y = zeros(d1,d2,T);

Your data are likely in uint16 format and when you export you clip the maximum value to 255 (uint8), which makes pixel with values greater than 255 (a LOT of them if your data is in uint16) appear white.

Otherwise you might want to use this line:

function tiff_write(Y,name)
   % Y should be 3D, name should end in .tif
   for t = 2:T
     imwrite(Y(:,:,t)/255,name,'WriteMode','append');
   end


来源:https://stackoverflow.com/questions/25771469/multipage-tiff-write-in-matlab-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!