MATLAB Answers

How to use imwrite from dicom to png

조회 수: 8(최근 30일)
mohd akmal masud
mohd akmal masud 2021년 8월 23일
댓글: Walter Roberson 2021년 9월 2일
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by