Question 1
Creating a sensible looking histogram from DICOM data
For question 1 you need to create a histogram of the CT image. When I created mine, I got a pretty
strange looking histogram (see below). There are high peaks in the middle and not much happening
on the sides
The reason for this strange looking histogram is that Matlab has plotted out data (that goes from -
1024 to 3072) to a completely different scale (-35000 to 35000). I can adjust the axis limits by using
the xlim command in Matlab. Setting the limits to -1024 and 3072 (you need to explain why I’ve
used these limits). This gives me the following histogram
Now obviously this histogram is pretty sparse. The reason is that the histogram has “binned” the
data using a low number of bins. You can use help imhist to find out how to change the binning of
the data. Re-binning gives me the following histogram which is obviously much more useful.
Image Processing Assignment – Question 1
Updated 29 September 2020
Using DICOM images in Matlab
We’ve used the imread command to read in a whole range of images to Matlab. When it comes to
DICOM images we have to do something different.
From the lectures we know that CT images range is value from about -1000 Hounsfield units to
about 3000 Hounsfield units. When CT images are stored they store these values. The problem is
that when Matlab tries to read in these images it doesn’t know what to do with this unusual range of
values.
To get around this we can use the dicomread function that is designed specifically for DICOM
images. Use the help function to find out how to use it correctly.
Once we do this you’ll notice that the image data has been input as data type int16. From the
lectures you’ll recall that we need twelve bits to store our CT images. There is no 12-bit option for
data in Matlab, as so it stores it in the next size up (16-bit). Typically image data is not 16-bits and so
some of the image processing tools that you might like to use (like imwrite) won’t work.
To get around this, reclass the data as type “im2double”. If your data is stored in the variable
“im”, then the command would be:
im_new = im2double(im);
I would suggest using the im2double command when you are using a command (like imwrite)
which cannot handle int16 data, as some of the functions (like histeq) are okay with using int16
data and will produce unexpected results if you use the im2double command.
Now you’re ready to manipulate the data. You may like to adjust the pixel values so that the
minimum pixel values are zero and the maximum pixel values are 1. You can do this using the linear
intensity transform from the Week 8 tutorial. This will certainly help you when you show the images
to screen or try to write them to a file. Image Processing Assignment – Question 1
Using Histogram Equalisation on Dicom Images
For question 1 you need to read your dicom image into Matlab, display the histogram, apply
histogram equalisation and display both the equalised image and the equalised histogram
Help Sheet 1 gives you some guidance on getting the histogram of the original image to look correct,
however, the same techniques cannot be used with the histeq function. Figure 1 shows the result
of histogram equalisation, the image only have a few shades of grey in it and the histogram is very
sparse. We want the histogram to have more distributed peaks and more greyscale levels in the
image.
Figure 1
If we apply the linear intensity transform to the original image, we change the range of values of the
original image (-1024 to 3000) to values between 0 and 1. Figure 2 shows the code that I used to
perform the linear intensity transform.
im_ct_lin = double((im_ct - min(im_ct(:))))/…
double(max(im_ct(:)) - min(im_ct(:)));
Figure 2
Figure 3 shows the original image (using imshow(im_ct,[]) ) and the “transformed” image. As
you can see there is no difference in how it looks, but the values of the greyscale values in each are
in different ranges.
Figure 3
If we apply the histeq function to the transformed image, we get a histogram like the one in Figure 4
(note that I specified the number of levels (or bins) in my histogram equalisation). As you can see the
histogram has lots of peaks and is well distributed.
Figure 4
The equalised image is shown in Figure 5. You can see lots of detail of the structure inside of the lung
that you couldn’t see in the original image.
Figure 5