How to use imwrite from dicom to png

6 vues (au cours des 30 derniers jours)
mohd akmal masud
mohd akmal masud le 23 Août 2021
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{:});

Réponse acceptée

Simon Chan
Simon Chan le 23 Août 2021
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 commentaires
mohd akmal masud
mohd akmal masud le 1 Sep 2021
in your code,
for k = 1 : size(I8,3)
end
what is 3?
Walter Roberson
Walter Roberson le 2 Sep 2021
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 .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by