Loading and Visualization
Learn to display a medical image stored in a file.
We'll cover the following...
Data and format
In this course, we’ll use open-source data. We’ll use the X-ray dataset for pneumothorax segmentation in the DICOM format. For the NIfTI-1 Data Format, we’ll use the CT dataset for liver cancer segmentation. This course does not require you to download the dataset to your computer. However, if you want to save it to your computer, see the course’s appendix.
DICOM
To work with DICOM files, we’ll use the pydicom library. We import all the libraries necessary for the work. After importing the required libraries, we read the file using the dcmread(). Let’s take the file as an example to display the given X-ray image.
As a result, the image data variable is of type pydicom.dataset.FileDataset since it contains not only the snapshot but also the metadata. To access the image, we need to use the pixel_array attribute of the DICOM image. Render the image using Matplotlib and use plt.cm.bone as a color scheme to make the image look like an X-ray.
The result will look like this:
Self-study task: Remove the plt.cm.bone color scheme, or try other color scheme.
NIfTI-1
The NIfTI DFWG (Data Format Working Group) suggested NIfTI-1 as a short-term approach to enhance the interoperability of functional MRI data analysis software packages.
Let’s look at an example to understand this approach.
- First, we import all the libraries necessary for this work.
- Then, we read the file using
load(). - We use
get_fdata()to get an image. - We work with the file
volume_pt5/volume-44.nii. Turn the image degrees, and look at the shape of the file contents. - The “depth” here means CT slices. We use
imshow()to visualize and CT slices.
Note: We can see the output of the array after turning the image by clicking on the
>symbol.
Let’s visualize a couple of CT slices ( and in this case):
Self-study task: Visualize various values of CT slices.