View DICOM images using Pydicom and Matplotlib
DICOM stands for Digital Imaging and Communications in Medicine. DICOM files were introduced to maintain uniformity among varied types of medical image modalities. It is a standard format to view, store, share and retrieve medical images.
Python offers a powerful module, pydicom to work with the DICOM files such as medical images, reports, and radiotherapy objects. pydicom reads modify and write data in DICOM files.
Run the following commands in the command prompt:
pip install dicom pip install matplotlib
pydicom enables us to work with DICOM files, in this article we will discuss the mechanism of viewing the DICOM file using pydicom and matplotlib. For reading the DICOM files we use pydicom package and to view the result we use matplotlib.
- Import module
- Read DICOM file using pydicom.data.data_manager.get_files() method
- Base : is base directory to recursively search as a string.
- Pattern : By default it is “*”. It is a string pattern which is used to filter the files.
- Provide 2 arguments: base and pattern
- Display the data as image i.e. on 2D regular raster.
- Display image
Note: Enter the location of the dcm file excluding the file name in the base of the variable name and enter the file name in the pass_dicom variable. In this case, the file is stored at a directory named dicom_image as shown:
Download the dcm file from here and rename it to: 1-12.dcm
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course