Understanding Photometric Interpretation
Looking at dicom tag (0028, 0004) Photometric Interpretation
DICOM images allows for various relationships between the pixel data and intended interpretation of how the image is displayed. The values are found in tag (0028,0004)
which lists the Photometric Interpretation
of the pixel data.
By using the easily accessible SLIM_SIIM
dataset from fastai
's list of databases, one can explore the head
of the dicom file which contains a list of tags pertaining to various aspects of the data.
pneumothorax_source = untar_data(URLs.SIIM_SMALL)
items = get_dicom_files(pneumothorax_source, recurse=True, folders='sm')
patient_one = dcmread(items[0])
patient_one
You can specifically call any of the tags, for this dataset the Photometric Interpretation
is MONOCHROME2
where the pixel data is represented as a single monochrome image plane.
patient_one.PhotometricInterpretation
According to the DICOM Standards Committee this interpretation can only be used when Samples per Pixel (0028, 0002)
has a value of 1. We can confirm this:
patient_one.SamplesPerPixel
patient_one.show()
More information about the different types of interpretations can be found here
Looking at another dataset, this time from the SIIM-ISIC Melanoma Classification competition.
msource = Path('D:/Datasets/Melanoma/test')
mitems = get_dicom_files(msource)
patient_two = dcmread(mitems[0])
patient_two
patient_two.PhotometricInterpretation
patient_two.SamplesPerPixel
In this case the interpretation is YBR_FULL_422
and the pixel data represents a color image described by one luminance (Y) and two chrominance planes (CB and CR). CB and CR values are sampled horizontally at half the Y rate and as a result there are half as many CB and CR values as Y values.
The out of the box show
function will not work on this dataset as it does not have Rescale Slope
listed in the head so we have to create one
def show_one(file):
""" function to view a dicom image when Rescale Slope is not noted"""
pat = dcmread(file)
trans = Transform(Resize(128))
dicom_create = PILDicom.create(file)
dicom_transform = trans(dicom_create)
return show_image(dicom_transform)
show_one(mitems[0])
But why does the image look unnatural?
This is because of the YBR_FULL_422
interpretation so we have to covert the interpretation from YBR_FULL_422
to RGB
so that it can look a bit more realistic.
Pydicom
provides a means of converting from one color space to another by using convert_color_space
where it takes the (pixel array, current color space, desired color space) as attributes. This is done by accessing the pixel_array and then converting to the desired color space
from pydicom.pixel_data_handlers.util import convert_color_space
arr = patient_two.pixel_array
convert = convert_color_space(arr, 'YBR_FULL_422', 'RGB')
show_image(convert)
That looks a lot better!