python-gdcm

3.2.2 · active · verified Thu Apr 16

python-gdcm provides unofficial Python 3 bindings for the Grassroots DiCoM (GDCM) C++ library. GDCM is a cross-platform library designed for handling DICOM medical files, supporting various transfer syntaxes including native, JPEG, JPEG 2000, JPEG-LS, RLE, and deflated. The library also includes XML representations of parts 3, 6, and 7 of the DICOM Standard. As of version 3.2.2, it is actively maintained with irregular but consistent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to read a DICOM image file using `gdcm.ImageReader`. It initializes a reader, sets the file name, attempts to read the file, and prints a success or error message.

import gdcm

# Assuming 'dicom_image_file.dcm' exists in the current directory
# Or provide a full path: reader.SetFileName('/path/to/your/dicom_image_file.dcm')

reader = gdcm.ImageReader()
reader.SetFileName("dicom_image_file.dcm")

if reader.Read():
    image = reader.GetImage()
    print(f"DICOM image successfully read. Dimensions: {image.GetDimension(0)}x{image.GetDimension(1)}")
    # Further processing, e.g., accessing pixel data:
    # pixel_array = image.GetBuffer()
else:
    print(f"Error: It was not possible to read 'dicom_image_file.dcm'.")

view raw JSON →