How can I create a 3D Tiff image (2D stack) from a 3D matrix?

95 ビュー (過去 30 日間)
Nicola Calliari
Nicola Calliari 2020 年 10 月 29 日
回答済み: Tim 2020 年 10 月 30 日
I have to save a 400x400x400 matrix (bw) in a stack of 2D tiff images.
I tried to us "imwrite" but it gives me this error:
Error using writetif (line 40)
Writing TIFFs with 400 components is not supported with IMWRITE. Use Tiff instead. Type "help Tiff" for more information.
Error in imwrite (line 546)
feval(fmt_s.write, data, map, filename, paramPairs{:});
But typing "help Tiff" I didn't find any solution.

回答 (1 件)

Tim
Tim 2020 年 10 月 30 日
Loop over your volume using imwrite(image_page_1, filename) for n == 1 and imwrite(image_page_nLargerThan1, filename, 'WriteMode', 'append') for n > 1. Here's some code I use to do this on a regular basis:
% Your example volume
tst = randn(400, 400, 400);
% Normalize for RGB colormap mapping:
scaled_tst = tst./max(tst, [], 'all');
% Colormap
cmp = parula;
% Write flag: run once with iwrite = false if you want to see what you are writing first
iwrite = true;
% File name:
fname = 'Test.tif';
for n = 1:size(tst, 3)
% Make an RGB image:
i_img = ind2rgb(round(scaled_tst(:, :, n)*256), cmp);
% Check what you are writing
image(i_img);
drawnow;
% Generate your tiff stack:
if iwrite
if n == 1
% First slice:
imwrite(i_img,fname)
else
% Subsequent slices:
imwrite(i_img,fname,'WriteMode','append');
end
end
disp(n)
end

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by