How to use imwrite from dicom to png

9 次查看(过去 30 天)
Hi all, I have 4D images. I want to exctract it to png every slice. Below my coding. But Got error. Anyone can help me?
I = dicomread('SPECT BENTUK LIVER.dcm');
I = squeeze(I);
I = uint8(255 * mat2gray( I));
imwrite(I,'SPECTbnetukLiver.png');
ERROR
Error using writepng (line 23)
PNG image data must be either MxN or MxNx3.
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});

采纳的回答

Simon Chan
Simon Chan 2021-8-23
It may contains more than one image and hence you need to save it one by one:
Following code for your reference:
[I, cmap] = dicomread('SPECT BENTUK LIVER.dcm');
J = squeeze(I);
[~,~,Nz] = size(J); % Check number of images
for k = 1:Nz
imwrite(J(:,:,k),cmap,sprintf('SPECTbnetukLiver_%02d.png',k)) % Save image one by one
end
  17 个评论
Walter Roberson
Walter Roberson 2021-9-2
szdim = size(A,dim) returns the length of dimension dim when dim is a positive integer scalar. Starting in R2019b, you can also specify dim as a vector of positive integers to query multiple dimension lengths at a time. For example, size(A,[2 3]) returns the lengths of the second and third dimensions of A in the 1-by-2 row vector szdim.
In other words, size(I8,3) is the number of "pages" (third dimension) that I8 has. You said "my image have 128x128x90 uint16" so the third dimension of that woud be 90 .

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by