使用imwrite保存tif 32位图像 [英] save tif 32 bit images by using imwrite
问题描述
我正在尝试将我的图像保存为tif 32位但我收到此错误:
I'm trying to save my images as tif 32 bits but I got this error:
Cannot write uint32 data to a TIFF file
这是我的代码:
for k=1:10
Id{k} = waverec2(t_C,L,'sym8');
filename= ['C:\Path \Id_number_' num2str(k) '.tif'];
Id{k}=uint32(Id{k});
imwrite(Id{k},filename);
end
我需要将图像保存为tif 32位。有什么想法?
I need to save my images as tif 32 bits. Any idea?
for k=1:10
Id{k} = waverec2(t_C,L,'sym8');
filename= ['C:\Path \Id_number_' num2str(k) '.tif'];
t = Tiff('filename','a')
Id{k}=uint32(Id{k});
t.write(Id{k});
end
但在Matlab下我收到此错误:
but under Matlab I got this error :
Error using tifflib
Unable to retrieve ImageLength.
Error in Tiff/getTag (line 784)
tagValue = tifflib('getField',obj.FileID,Tiff.TagID.(tagId));
Error in Tiff/writeAllStrips (line 1660)
h = obj.getTag('ImageLength');
Error in Tiff/write (line 1228)
obj.writeAllStrips(varargin{:});
推荐答案
虽然TIFF格式支持 uint32
,Matlab没有。接受的intput类是double,single,uint8,uint16或logical。
Although the TIFF format does support uint32
, Matlab does not. Accepted intput classes are double, single, uint8, uint16, or logical.
如果您可以接受丢失精度,则可以将其转换为 uint16
(使用 im2uint16
)。如果不是,您可以使用 im2double
将其转换为 double
。请注意 im2double
与 double(your_uint16_image)
不同,所以要小心。
If you losing precision is acceptable to you, you can convert it to uint16
(use im2uint16
). If it is not, you can convert it to double
with im2double
. Note that im2double
is not the same as double (your_uint16_image)
so be careful with it.
如果这些选项都不可接受,您可能需要使用libtiff编写自己的mex代码或使用Octave(这将需要使用量子深度32构建的GraphicsMagick)。
If none of those options are acceptable, you might need to write your own mex code using libtiff or use Octave (which will require GraphicsMagick built with quantum depth 32).
编辑:显然还有一个新的TIFF类(见下面的答案),它提供了一个直接接口。
apparently there is also a new TIFF class (see answer below) which gives a direct interface to it.
这篇关于使用imwrite保存tif 32位图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!