pydicom#

An easy to use Python package for creating, reading, modifying and writing DICOM datasets and File-sets, with optional support for converting compressed and uncompressed Pixel Data to NumPy ndarrays (and back again).

Install#

pip install pydicom
conda install -c conda-forge pydicom

For more detailed instructions, see the installation guide.

Examples#

>>> from pydicom import dcmread
>>> ds = dcmread("path/to/dataset")
>>> ds.PatientName
'CompressedSamples^CT1'
>>> ds.PatientName = "Citizen^Jan"
>>> print(ds)
...
(0010,0010) Patient's Name                      PN: 'Citizen^Jan'
(0010,0020) Patient ID                          LO: '4MR1'
...
>>> ds.save_as("modified.dcm")
>>> from pydicom import examples
>>> from pydicom.fileset import FileSet
>>> path = examples.get_path("dicomdir")  # Example DICOMDIR dataset
>>> fs = FileSet(path)
>>> fs.find_values("PatientID")
['77654033', '9890234']
>>> ds = fs.find(PatientID='77654033')[0].load()
>>> type(ds)
<class 'pydicom.dataset.FileDataset'>
>>> ds.PatientID
'77654033'
>>> from pydicom import dcmread, examples
>>> path = examples.get_path("mr")  # Example MR dataset
>>> ds = dcmread(path)
>>> arr = ds.pixel_array  # requires NumPy, see the installation guide
>>> arr
array([[ 905, 1019, 1227, ...,  302,  304,  328],
   [ 628,  770,  907, ...,  298,  331,  355],
   [ 498,  566,  706, ...,  280,  285,  320],
   ...,
   [ 334,  400,  431, ..., 1094, 1068, 1083],
   [ 339,  377,  413, ..., 1318, 1346, 1336],
   [ 378,  374,  422, ..., 1369, 1129,  862]],
  shape=(64, 64), dtype=int16)

More usage examples can be found here.

Documentation#

Quick start

If you’re new to pydicom start here for an introduction to reading and manipulating DICOM datasets, and accessing Pixel Data as a NumPy ndarray.

User guide

The user guide covers usage of pydicom’s core classes and functions and how they’re related to the relevant parts of the DICOM Standard.

Learning resources

Our collection of code examples, tutorials and guides should help you learn the basics of pydicom, as well as more advanced topics.

API reference

The API reference documentation contains detailed descriptions of the classes, functions, modules and other objects included in pydicom.