gpt4 book ai didi

image - 在 matlab 中将多页 tif 写入文件

转载 作者:行者123 更新时间:2023-12-02 16:51:23 25 4
gpt4 key购买 nike

我正在尝试将多页(确切地说是 1024 页)写入文件。

for frame=1:num_images
imwrite(output(:,:,frame), 'output.tif', 'tif', 'WriteMode', 'append', 'compression', 'none');
end

我尝试了这个,但是 imwrite 不支持将 Int32 写入 tiff。我也尝试过

tiffObj = Tiff('output.tif', 'w');
tiffObj.setTag('ImageLength', x_size);
tiffObj.setTag('ImageWidth', y_size);
tiffObj.setTag('Photometric', Tiff.Photometric.MinIsBlack);
tiffObj.setTag('BitsPerSample', 32);
tiffObj.setTag('SamplesPerPixel', 1);
tiffObj.setTag('RowsPerStrip', 64);
tiffObj.setTag('SampleFormat', Tiff.SampleFormat.Int);
tiffObj.setTag('TileWidth', 128);
tiffObj.setTag('TileLength', 128);
tiffObj.setTag('Compression', Tiff.Compression.None);
tiffObj.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
tiffObj.setTag('Software', 'MATLAB');
tiffObj.write(output);
tiffObj.close();

我 imread() 的 tif 每帧有 1 个 SamplesPerPixel,但是当我尝试使用相同的值时,我得到

SamplesPerPixel is 1, but the number of image planes provided was 1204.

如果我将其设置为 1204 Imagej 会提示

Unsupported SamplesPerPixel: 1204

这真是令人沮丧。

最佳答案

将多个页面写入 TIFF 文件的正确方法是调用 Tiff.writeDirectory每页(2D 图像)写入后。我同意,MATLAB文档那里不是很清楚,知道LibTIFF帮助使用 Tiff 类。例如:

image = zeros([140,160,16],'uint8'); % this is the image we'll write, should have some actual data in it...

t = Tiff('testing.tif','w');
tagstruct.ImageLength = size(image,1);
tagstruct.ImageWidth = size(image,2);
tagstruct.SampleFormat = 1; % uint
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 8;
tagstruct.SamplesPerPixel = 1;
tagstruct.Compression = Tiff.Compression.Deflate;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
for ii=1:size(image,3)
setTag(t,tagstruct);
write(t,image(:,:,ii));
writeDirectory(t);
end
close(t)

关于image - 在 matlab 中将多页 tif 写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29008188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com