2
votes

I have a dicom image that when I open it in MATLAB it is like this:

enter image description here

However when I see that via dicomviewer it is like this:

enter image description here

How can I save these dicom images without loosing their information in .jpeg format due to compression process? I want to save the image so that I can retrieve the same information as I get from the respective dicom image. Is it possible?

1
Do you want to see the same image on MATLAB, which is currently unavailable (black image)?Jeon
The image you see in Matlab is showing the full range of grey values. If you adjust the contrast (for example by using imshow(image,[])), then you will see the same as you get with the dicom viewerDave

1 Answers

10
votes

DICOM image data is typically stored as 16-bit unsigned integers, so you'll want to make sure that your image is stored within a uint16 matrix prior to saving so MATLAB knows to save it as such. Also, for some image formats, MATLAB requires that we explicitly state the bit depth.

% Save as a 16-bit Baseline JPEG with the highest quality
imwrite(uint16(data), 'image.jpg', 'Quality', 100, 'BitDepth', 16);

% Save as a 16-bit Lossless JPEG
imwrite(uint16(data), 'image.jpg', 'Mode', 'lossless', 'BitDepth', 16)

% Save as a 16-bit JPEG 2000 Image
imwrite(uint16(data), 'image.jp2', 'Mode', 'lossless')

If you don't need a JPEG for any particular reason, I would recommend a PNG (lossless).

% Save as 16-bit PNG
imwrite(uint16(data), 'image.png')

See the full list of available 16-bit formats here.

For visualization in MATLAB, you can specify the second input to imshow (or use imagesc) to automatically scale the displayed gray scale values to the data within the image

imshow(data, [])    % or imagesc(data); axis image;