MATLAB Answers

how to convert dicom image to png

47 views (last 30 days)
Hi all,
i want to convert my dicom image to png image.
below my coding, but error. Anyone can help me?
[I, map]=dicomread('lung.dcm');
imwrite(I,map,'lung.png','png');
ERRORR!!!!
Error using imwrite>parse_inputs (line 628)
The colormap should have three columns.
Error in imwrite (line 440)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
CAN HELP ME?

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 23 Jan 2021
I imagine you looked at what map was. Did that not give you any clue as to why it was not 3 columns? What was it? Maybe it's empty, in which case you'd not pass it in to imwrite.

  8 Comments

Show 5 older comments
mohd akmal masud
mohd akmal masud on 24 Jan 2021
also error for change to RGB
>> [grayImage, map] = dicomread('lung.dcm');
>> rgbImage = ind2rgb(grayImage, map);
Index in position 1 exceeds array bounds.
Error in matlab.images.internal.ind2rgb (line 24)
rgb(1:height, 1:width, 1) = reshape(cm(indexedImage, 1), [height width]);
Error in ind2rgb (line 17)
r = matlab.images.internal.ind2rgb(a, cm);
Image Analyst
Image Analyst on 24 Jan 2021
You can't do that. You have to do it like I showed you - inside an "if" block. You can't convert a gray scale or indexed image to RGB if there is no colormap.
And for the gray scale image I assume you got that working already by doing what it told you and casting your image to uint8 with the im2uint8() or uint8() function
grayImage = im2uint8(grayImage);
imwrite(grayImage, outputFileName);
mohd akmal masud
mohd akmal masud on 24 Jan 2021
oh i see..mean there is no map, then cannot convert it to RGB.
yes, for im2unit8 done.
thank you sir for your explanation. thank you so much.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!