pydicom is a pure Python package for working with DICOM files.
It lets you read, modify and write DICOM data in an easy "pythonic" way. As a pure Python package,
pydicom can run anywhere Python runs without any other requirements, although if you're working
with Pixel Data then we recommend you also install NumPy.
Note that pydicom is a general-purpose DICOM framework concerned with
reading and writing DICOM datasets. In order to keep the
project manageable, it does not handle the specifics of individual SOP classes
or other aspects of DICOM. Other libraries both inside and outside the
pydicom organization are based on pydicom
and provide support for other aspects of DICOM, and for more
specific applications.
Examples are pynetdicom, which
is a Python library for DICOM networking, and deid,
which supports the anonymization of DICOM files.
Converting JPEG, JPEG-LS or JPEG 2000 compressed Pixel Data to an ndarray requires installing one or more additional Python libraries. For information on which libraries are required, see the pixel data handler documentation.
Information on compressing Pixel Data using one of the below formats can be found in the corresponding encoding guides. These guides cover the specific requirements for each encoding method and we recommend you be familiar with them when performing image compression.
JPEG-LS, JPEG 2000
Compressing image data from an ndarray or bytes object to JPEG-LS or JPEG 2000 requires installing the following:
Compressing using RLE requires no additional packages but can be quite slow. It can be sped up by installing pylibjpeg with the pylibjpeg-rle plugin, or gdcm.
import matplotlib.pyplot as plt
from pydicom import dcmread, examples
# The path to the example "ct" dataset included with pydicom
path: "pathlib.Path" = examples.get_path("ct")
ds = dcmread(path)
# `arr` is a numpy.ndarray
arr = ds.pixel_array
plt.imshow(arr, cmap="gray")
plt.show()
Contributing
We are all volunteers working on pydicom in our free time. As our
resources are limited, we very much value your contributions, be it bug fixes, new
core features, or documentation improvements. For more information, please
read our contribution guide.
Alternatives
Use instead of pydicom: tools that do the same job, closest first.
pylibjpegPythie’s Index: 23A Python framework for decoding JPEG and decoding/encoding DICOM RLE data, with a focus on supporting pydicom1.4M downloads/mo