DICOM to grayscale in matlab -


how can convert dicom image grayscale image in matlab?

thanks.

i'm not sure specific dicom image talking not grayscale already. following piece of code demonstrates how read , display dicom image:

im = dicomread('sample.dcm'); % im of type uint16, in grayscale imshow(im, []); 

if want uint8 grayscale image, use:

im2 = im2uint8(im); 

however keep of precision possible, it's best do:

im2 = im2double(im); 

to stretch limits temporarily when displaying image, use:

imshow(im2, []); 

to stretch limits permanently (for visualization not analysis), use:

% im3 elements between 0 , 255 (uint8) or 0 , 1 (double) im3 = imadjust(im2, stretchlim(im2, 0), []);  imshow(im3); 

to write grayscale image jpg or png, use:

imwrite(im3, 'sample.png'); 

update

if version of matlab not have im2uint8 or im2double, assuming dicom image uin16 quick workaround convert dicom image more manageable format be:

% convert uint16 values double values % im = double(im); % keep current relative intensity levels analysis % involving real values of intensity im2 = im/2^16 % if displaying, create new image limits stretched maximum  % visualization purposes. not use image % calculations involving intensity value. im3 = im/(max(im(:)); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -