Sunday, September 22, 2024
Google search engine
HomeLanguagesView DICOM images using pydicom and matplotlib

View DICOM images using pydicom and matplotlib

Prerequisite : 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, modifies and write data in DICOM files.Ā 

Installation

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.

Input given

The path where the dicom file is stored is passed as an argument to data_manager.get_files method.

Using pydicom with matplotlibĀ 

Explanation:

  • Import module
  • Read DICOM file using pydicom.data.data_manager.get_files() method

Syntax :Ā 

pydicom.data.data_manager.get_files(base,pass_dicom)[0]

Parameter:

  • 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
  • Displays 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 variable names base 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

Compare the path shown in the address bar with the values stored in the variable base and pass_dicom

Program:

Python3




import matplotlib.pyplot as plt
import pydicom
import pydicom.data
Ā Ā 
# Full path of the DICOM file is passed in base
base = r"C:\Users\Ajit Gupta\Documents\dicom image"
pass_dicom = "1-12.dcm"Ā  # file name is 1-12.dcm
Ā Ā 
# enter DICOM image name for pattern
# result is a list of 1 element
filename = pydicom.data.data_manager.get_files(base, pass_dicom)[0]
Ā Ā 
ds = pydicom.dcmread(filename)
Ā Ā 
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)Ā  # set the color map to bone
plt.show()


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments

ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
źøˆģ²œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
źµ¬ģ›”ė™ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ˜¤ģ‚°ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ•ˆģ–‘ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė™ķƒ„ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ„œģšøģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶„ė‹¹ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ź³”ė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź³ ģ–‘ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ģ„±ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ²œķ˜øė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?