How to use imwrite from dicom to png

6 visualizaciones (últimos 30 días)
mohd akmal masud
mohd akmal masud el 23 de Ag. de 2021
Comentada: Walter Roberson el 2 de Sept. de 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{:});

Respuesta aceptada

Simon Chan
Simon Chan el 23 de Ag. de 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 comentarios
mohd akmal masud
mohd akmal masud el 1 de Sept. de 2021
in your code,
for k = 1 : size(I8,3)
end
what is 3?
Walter Roberson
Walter Roberson el 2 de Sept. de 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 .

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by