How can I convert a DICOM image to a jpeg image or bmp image?

In my project, I need an medical images in bmp form, but the problem they didn't exist with that form, so I must convert a DICOM image format to bmp, I have write the code but a problem stop when I want to save X,MAP obtained, X is int16, than what should I do?.

3 comentarios

Hope this helps you, I was looking for the same and found .
I = dicomread('IM (9).dcm');
[filename, pathname] = uigetfile('IM (9).dcm', 'Open DICOM Image');% Open only DICOM image
[X,MAP]=dicomread(fullfile(pathname, filename));
image8 = uint8(255 * mat2gray(X));
imwrite(image8,'MRI-IM.bmp', 'bmp');
C = imread ('MRI-IM.bmp');
imshow(C);
If the returned MAP is non-empty then you need to
X = ind2rgb(X, MAP);
If you are certain that the returned MAP will be empty then you should not return it as an output from DICOMREAD.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 27 de Feb. de 2015
Why do you need them in that form? You can read the DICOM images in to your m-file with dicomread() so why do you need to read them in from a BMP with imread()?

11 comentarios

Hi Image Analyst, Firstly thank you for the answer. I know what you want to say, but in compression how can I calculate CR (compression ratio).
How about the size on disk divided by the full size? Use imfinfo() or dir() to get the size in bytes when it's compressed into a file on disk.
Good idea, I will try to see it Inchaa-l'Allah.
Said BOUREZG
Said BOUREZG el 28 de Feb. de 2015
Editada: Said BOUREZG el 28 de Feb. de 2015
The dcm format is not acceptable by the two function used in your answer.
Which two functions? dicomread() will certainly read valid dicom files. imread() won't (and I never said it did). imfinfo() and dir() don't care what the format is. dir() certainly doesn't, though I'm not sure about imfinfo(). If imfinfo() doesn't, then just use dir() to get the size info.
If you want further help, attach your m-file and image file.
Said BOUREZG
Said BOUREZG el 1 de Mzo. de 2015
Editada: Image Analyst el 1 de Mzo. de 2015
[filename, pathname] = uigetfile('*.dcm', 'Open DICOM Image');
if isequal(filename, 0) || isequal(pathname, 0)
disp('Image input canceled.');
else
[X,MAP]=dicomread(fullfile(pathname, filename));
imwrite(X,'myfile.bmp', 'bmp');
end;
Yes, so what happened when you tried to use dicomread() to read the file into variable X? Did you get an error message? Exactly why do you think it's "unacceptable"?
No problem in using dicomread(), but the problem when I want to save it as bmp image format. thank you for your help.
Please read this.
Again, what's the error message, or how do you know it didn't work? Why do you think it's "unacceptable"? I'm saying that imwrite() does work. If you say it doesn't , then you must give proof. How else can I help you if you don't show us why it's not working?
Regarding your "Answer", if you want it to be uint8(), use mat2gray():
image8 = uint8(255 * mat2gray(X));
imshow(image8, []);
Said BOUREZG
Said BOUREZG el 1 de Mzo. de 2015
Editada: Said BOUREZG el 1 de Mzo. de 2015
Yes, it works, thank u very much sir.. I hope that you will find the Eternal happiness source Sorry I was not here to see your last answer.

Iniciar sesión para comentar.

Más respuestas (2)

Said, try this:
[filename, pathname] = uigetfile('*.dcm', 'Open DICOM Image');
if isequal(filename, 0) || isequal(pathname, 0)
uiwait(helpdlg('Image reading canceled.'));
else
[X,MAP]=dicomread(fullfile(pathname, filename));
subplot(1,2,1);
imshow(X, []);
title('16 bit image.', 'FontSize', 30);
% Convert to 8 bit.
image8 = uint8(255 * mat2gray(X));
subplot(1,2,2);
imshow(image8, []);
title('8 bit image.', 'FontSize', 30);
imwrite(image8,'myfile.bmp');
end

2 comentarios

I get this error
Error using images.internal.imageDisplayValidateParams>validateCData (line 115) Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27) common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78) common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 240) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in untitled111 (line 7) imshow(X, []);
the image is multiplanar, some idea
You cannot use imshow() to display more than 3 planes of a multiplanar image.
You need to use a volume viewer such as volumeViewer (R2017a or later), or you need to treat the planes as slices to be displayed, such as getting imdisp() or its follow-on SC from the File Exchange and using
imdisp(reshape(X, size(X,1), size(X,2), 1, size(X,3)))

Iniciar sesión para comentar.

Said BOUREZG
Said BOUREZG el 1 de Mzo. de 2015
yes, imwrite() work, but the image (.bmp) can't appear, X matrix before imwrite values are int16 so the range is not 0 to 255, so here when I save it as bmp I see only black and white. the dicom image is attached, run it and tell me

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Feb. de 2015

Editada:

el 26 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by