MATLAB中的多页Tiff写不起作用 [英] Multipage Tiff write in MATLAB doesn't work

查看:166
本文介绍了MATLAB中的多页Tiff写不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的函数读取Tiff,它工作正常,但是当我尝试使用我的写函数将相同的Tiff写回不同的文件时,它全部是255。有谁知道如何解决这一问题?谢谢,Alex。

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


推荐答案

尝试使用此行:

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

而不是这一个:

Y = zeros(d1,d2,T);

您的数据可能是uint16格式,导出时剪辑的最大值为255(uint8) ,使得值大于255的像素(如果你的数据在uint16中,则很多)显示为白色。

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

这篇关于MATLAB中的多页Tiff写不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆