필터 지우기
필터 지우기

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

조회 수: 28 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by