or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-utilities.mddata-elements.mddataset-manipulation.mdfile-operations.mdindex.mdpixel-data-processing.mdsequences-collections.mdtags-and-uids.mdvalue-representations.md
tile.json

tessl/pypi-pydicom

A pure Python package for reading and writing DICOM data

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pydicom@3.0.x

To install, run

npx @tessl/cli install tessl/pypi-pydicom@3.0.0

index.mddocs/

PyDicom

A pure Python package for reading and writing DICOM (Digital Imaging and Communications in Medicine) files. PyDicom provides comprehensive functionality for working with medical imaging data, offering both high-level convenience functions for common tasks and low-level access for advanced DICOM manipulation.

Package Information

  • Package Name: pydicom
  • Language: Python
  • Installation: pip install pydicom

Core Imports

import pydicom

Most commonly used imports:

from pydicom import dcmread, dcmwrite
from pydicom.dataset import Dataset, FileDataset, FileMetaDataset
from pydicom.dataelem import DataElement
from pydicom.sequence import Sequence

For pixel data operations:

from pydicom import pixel_array, iter_pixels
# Or more specific:
from pydicom.pixels.utils import pixel_array, iter_pixels
from pydicom.pixels import compress, decompress

For configuration and utilities:

from pydicom import config
from pydicom.config import debug, DS_numpy, DS_decimal
from pydicom.datadict import dictionary_description, keyword_for_tag, tag_for_keyword

For advanced usage:

from pydicom.tag import Tag
from pydicom.uid import UID, generate_uid
from pydicom.valuerep import PersonName, DA, TM, DT
from pydicom.data import get_testdata_file

Basic Usage

from pydicom import dcmread, dcmwrite
from pydicom.dataset import Dataset

# Read a DICOM file
dataset = dcmread("path/to/file.dcm")

# Access DICOM elements
patient_name = dataset.PatientName
study_date = dataset.StudyDate

# Modify elements
dataset.PatientName = "Anonymous"
dataset.PatientID = "12345"

# Add new elements
dataset.add_new(0x0010, 0x1030, "DS", "75.5")  # Patient Weight

# Save to new file
dcmwrite("output.dcm", dataset)

# Work with pixel data (requires NumPy)
if hasattr(dataset, 'pixel_array'):
    pixels = dataset.pixel_array
    print(f"Image shape: {pixels.shape}")
    print(f"Data type: {pixels.dtype}")

Architecture

PyDicom follows the DICOM standard structure and provides a comprehensive object model:

  • Dataset: The central container representing a DICOM dataset with dict-like access to data elements
  • DataElement: Individual DICOM data elements containing tag, VR (Value Representation), and value
  • Sequence: Containers for nested datasets within DICOM sequences
  • Tag: DICOM tag identification using (group, element) tuples
  • UID: Specialized string class for DICOM Unique Identifiers
  • Pixel Processing: Comprehensive pixel data handling with support for various compression formats

The library supports the complete DICOM standard including advanced features like structured reporting, overlays, waveforms, and extensive pixel data processing capabilities.

Capabilities

File Operations

Core functionality for reading and writing DICOM files with support for various transfer syntaxes, partial reading, and metadata extraction.

def dcmread(fp, force=False, specific_tags=None, stop_before_pixels=False): ...
def dcmwrite(filename, dataset, write_like_original=True): ...

File Operations

Dataset Manipulation

Comprehensive dataset management including element access, modification, validation, and serialization with full support for the DICOM data model.

class Dataset:
    def __getitem__(self, key): ...
    def __setitem__(self, key, value): ...
    def add(self, data_element): ...
    def add_new(self, tag, VR, value): ...
    def save_as(self, filename): ...

Dataset Manipulation

Data Elements

Individual DICOM data element handling with support for all Value Representations (VRs) and proper type conversion.

class DataElement:
    def __init__(self, tag, VR, value): ...
    @property
    def keyword(self): ...
    @property
    def description(self): ...

Data Elements

Pixel Data Processing

Advanced pixel data manipulation including array extraction, compression, decompression, color space conversion, and various image processing operations.

def pixel_array(dataset): ...
def iter_pixels(dataset): ...
def compress(dataset, transfer_syntax_uid): ...
def apply_windowing(arr, dataset): ...

Pixel Data Processing

Tags and UIDs

DICOM tag and UID management with dictionary lookups, keyword conversion, and UID generation capabilities.

class Tag:
    def __init__(self, *args): ...
class UID(str):
    def is_transfer_syntax(self): ...
def generate_uid(): ...

Tags and UIDs

Value Representations

Specialized handling for DICOM Value Representations including dates, times, person names, and numeric types with proper validation and conversion.

class PersonName:
    @property
    def family_name(self): ...
    @property
    def given_name(self): ...
class DA:  # Date
    def __init__(self, val): ...
class TM:  # Time
    def __init__(self, val): ...

Value Representations

Sequences and Collections

Management of DICOM sequences and multi-value elements with proper nesting and validation support.

class Sequence(list):
    def __init__(self, iterable=None): ...
class MultiValue:
    def __init__(self, type_constructor, iterable): ...

Sequences and Collections

Configuration and Utilities

Package configuration, debugging tools, data dictionary access, and various utility functions for DICOM file analysis and manipulation.

def debug(debug_on=True): ...
def dictionary_description(tag): ...
def keyword_for_tag(tag): ...
def tag_for_keyword(keyword): ...

Configuration and Utilities

Types

from typing import Union, Optional, List, Dict, Any, BinaryIO, Tuple
from pathlib import Path

# Core types
TagType = Union[int, Tuple[int, int], str]
VRType = str
ValueType = Any
FilePathType = Union[str, Path, BinaryIO]

# Pixel data types
ArrayType = Any  # NumPy ndarray when available
CompressionType = str
TransferSyntaxType = str