Is it possible to obtain a binary image representation of a DICOM IMAGE?

6 views (last 30 days)
I have converted a DICOM image to a grayscale image first and then used then used 'im2bw' function to get the binary image but the output is totally different from the input.the code is given as:
clear all;
X = dicomread('000018.dcm');
figure,imshow(X,[]),title('Original Dicom Image');
img = double(X);
img = (img - min(img(:))) / (max(img(:)) - min(img(:)));
img = uint8(255*img);
figure,imshow(img,[]),title('Original Grayscale Image');
The input dicom image is:
But the output after im2bw is:
Can i get an image like this ?
I got this binary image by converting the dicom file to jpeg and then using im2bw but it results in compression and hence loss of data. I need to get it directly from the dicom image. Is it possible?

Accepted Answer

Image Analyst
Image Analyst on 2 Mar 2015
You just threshold
binaryImage = grayImage > lowThreshold & grayImage < highThreshold;
imshow(binaryImage);
Of course it results in a loss of data - you're converting a gray scale image to a binary image with only two gray levels. What do you expect?
There is no need to convert to JPEG, and in fact, you are not even doing that, so that's good.
  2 Comments
Pratik Datta
Pratik Datta on 3 Mar 2015
Thank you for your reply.
Loss of data is indeed, not a concern,as correctly pointed out by you.Thanks.
What I have done now is I applied histogram equalization using the function 'histeq' on the image and after that the thresholding worked properly.
I think the negative value in the image matrix was causing the problem.
There were negative values (-2000) surrounding the circular region but all other values were positive.I dont know the reason behind this.
However,after histogram equallization, the intensity was well spread over the 16 bit-signed range and a better contrast was obtained.Also thresholding was done using 'im2bw' and worked properly.
I=dicomread('000018.dcm');
J=histeq(I);
figure(),imshow(J);
bin_img=im2bw(J)
figure(),imshow(bin_img);
Image Analyst
Image Analyst on 3 Mar 2015
HIstogram equalization merely spreads out the histogram bins over a different range. It's totally unnecessary for thresholding, and in fact, usually produces harsh unnatural looking images. There is no binary image that you can't get without running a histogram equalization so it's unnecessary. In other words, you can get the same binary image with or without histogram equalization, it's just that the threshold gray level you choose will be different. So skip the equalization and save some time.
To set values of -2000 (or any negative values) to 0 just do this:
grayImage(grayImage < 0) = 0;
Maybe that will allow graythresh() to pick a gray level automatically without doing histogram equalization.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!