pydicom

Python library for working with DICOM medical imaging files — use for reading, writing, or modifying CT/MRI/X-ray/ultrasound data, extracting pixel data, anonymizing DICOM files, working with metadata tags, and converting DICOM to other formats.

Read, write, and anonymize DICOM medical imaging files

Source K-Dense AI
License MIT
First documented

Trigger phrases

Phrases that activate this skill when typed to Claude Code:

  • read DICOM file
  • extract pixel data
  • anonymize DICOM
  • DICOM metadata
  • medical image processing

What it does

pydicom is a Claude Code skill from K-Dense AI’s scientific-agent-skills repo. It turns Claude into a pydicom expert for working with DICOM — the standard file format for medical imaging — covering file reading and writing, pixel array extraction (with proper rescale slope/intercept and modality LUT application), metadata tag access, anonymization (removing patient identifiers), compressed DICOM handling, and format conversion (DICOM to PNG/TIFF/NIfTI).

A session produces Python code that reads DICOM files correctly, applies the necessary transforms to get meaningful pixel values (Hounsfield units for CT, for example), and outputs the requested format or analysis.

When to use it

Reach for it when:

  • You need to read CT, MRI, X-ray, or ultrasound DICOM files and access pixel data or metadata in Python
  • You’re anonymizing DICOM datasets for research — removing PHI (patient name, DOB, accession number) in compliance with HIPAA requirements
  • You’re converting DICOM series to formats for deep learning pipelines (NIfTI, numpy arrays, PNG slices)

When not to reach for it:

  • DICOM PACS networking, worklist management, or DIMSE operations — pydicom is a file library, not a DICOM network client
  • Large-scale DICOM processing pipelines requiring GPU acceleration — consider specialized medical imaging frameworks

Install

Copy the SKILL.md from K-Dense AI’s pydicom folder into .claude/skills/pydicom/ in your project. Install via pip install pydicom. Compressed transfer syntaxes (JPEG 2000, RLE) require pylibjpeg or gdcm as additional packages.

Trigger phrases: “read DICOM file”, “extract pixel data”, “anonymize DICOM”, “DICOM metadata”.

What a session looks like

A typical session has three phases:

  1. File loading and inspection. Claude reads the DICOM file with pydicom.dcmread() and prints key tags: patient ID (if not yet anonymized), study date, modality, series description, image dimensions, and transfer syntax.
  2. Pixel data extraction. Claude applies the correct pixel value transformation: rescale slope and intercept for CT (Hounsfield units), photometric interpretation for X-ray (MONOCHROME1 vs. MONOCHROME2 windowing direction), and decompression for compressed transfer syntaxes.
  3. Output or anonymization. The pixel array is returned as a numpy array for analysis, or a new anonymized DICOM file is written with all PHI tags removed or replaced with pseudonyms per the DICOM standard de-identification attributes.

Receipts

Where it works well:

  • Reading CT DICOM series and converting to Hounsfield units — Claude applies rescale slope/intercept correctly, which is the most common source of wrong pixel values in amateur DICOM code
  • DICOM de-identification for research datasets — the standard list of Type 2 and Type 3 tags that must be removed is handled systematically

Where it backfires:

  • Compressed DICOM files (JPEG 2000, JPEG Lossless) require additional system libraries that aren’t always available in default environments; the error messages from missing compression libraries are not always clear
  • Multi-frame DICOM (cine, enhanced MR, enhanced CT) has a different pixel data structure than single-frame; code written for single-frame files fails silently on multi-frame with wrong shapes

Pattern that works: always check ds.file_meta.TransferSyntaxUID before attempting pixel extraction — if it’s a compressed transfer syntax, confirm the decompression library is available before attempting ds.pixel_array.

Source and attribution

Originally authored by K-Dense Inc.. The canonical SKILL.md lives in the pydicom folder of their public scientific-agent-skills repository.

License: MIT. Install, adapt, and redistribute with attribution preserved.

This page documents the skill from a practitioner’s perspective. For the formal spec and any updates, defer to the source repo.