pydicom-medical-imaging
Pure Python DICOM for medical imaging (CT, MRI, X-ray, ultrasound). Read/write DICOM, pixels as NumPy, edit tags, windowing (VOI LUT), PHI anonymization, build DICOM, series→3D volumes. Use histolab for WSI pathology; nibabel for NIfTI.
npx skills add BioTender-max/awesome-bio-agent-skills --skill pydicom-medical-imaging --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides an AI agent to read, write, and modify DICOM files, extract and manipulate pixel data as NumPy arrays, apply windowing, anonymize PHI, and build DICOM files from scratch. It covers converting DICOMs to standard formats, handling multi-frame and color images, and assembling DICOM series into 3D volumes.
How it works
The skill provides concrete Python-centered procedures and code samples across modules:
- Module 1: Reading and Metadata Access — read DICOMs, access metadata by attribute or tag, and optionally read DICOMDIR structures.
- Module 2: Pixel Data Extraction — extract pixel data, apply modality LUT, VOI LUT, manual windowing, handle color spaces, and multi-frame data.
- Module 3: Image Conversion — convert pixel data to PNG/JPEG, normalize to 8-bit, batch convert directories of DICOMs to images.
- Module 4: Metadata Modification and Anonymization — modify tags, add or delete attributes, generate new UIDs, and perform PHI anonymization with a defined tag list.
- Module 5: Writing DICOM from Scratch — create FileDataset with proper File Meta header, populate required metadata, and assign PixelData from NumPy arrays for new DICOMs.
- Module 6: Series Processing and 3D Volumes — load, sort by spatial position, stack into 3D volumes, compute voxel spacing, and report HU range.
The skill prescribes specific function calls, file names, and tool usage (e.g., pydicom.dcmread, apply_voi_lut, generate_uid, PixelData, Image from PIL, and standard DICOM tags).
When to use it
Use when you need to read or rewrite DICOM metadata, anonymize PHI, extract/visualize pixel data, convert to standard image formats, assemble 3D volumes from a series, or generate new DICOM files from NumPy data.
What it can touch
- Tools: pydicom, numpy, pillow, PIL.Image, possibly PIL for image export, and utilities like apply_voi_lut, apply_modality_lut, convert_color_space, and generate_uid.
- Files: DICOM files (*.dcm, *.ima), DICOMDIR, new.dcm, modified.dcm, anonymized.dcm, output.png, output.jpg, new.dcm, ct_series/ directory, dicom_files/, images/
Caveats
- License: MIT is stated in the frontmatter; executable details rely on pydicom and optional codecs.
- It warns about handling compressed transfer syntaxes and requires appropriate codecs (e.g., pylibjpeg, python-gdcm) for pixel_array on compressed files.
- Some sections rely on institutional PHI policies for tag removal; a predefined PHI_TAGS list is provided.
- No guarantees of specific outputs; actual results depend on input data and environment configuration.
# Pydicom Medical Imaging ## Overview Pydicom is a pure Python library for reading, writing, and modifying DICOM (Digital Imaging and Communications in Medicine) files. It provides access to DICOM metadata tags and pixel data as NumPy arrays, supporting CT, MRI, X-ray, ultrasound, and other medical imaging modalities. The library handles compressed and uncompressed transfer syntaxes with optional codec plugins. ## When to Use - Reading DICOM files and extracting metadata (patient info, study parameters, imaging settings) - Extracting pixel data from DICOM images for analysis or visualization - Converting DICOM images to standard formats (PNG, JPEG, TIFF) - Anonymizing DICOM files by removing Protected Health Information (PHI) - Modifying DICOM metadata tags for relabeling or correction - Creating DICOM files from scratch (e.g., wrapping NumPy arrays as DICOM) - Processing CT/MRI series into 3D volumetric arrays for reconstruction - Extracting frames from multi-frame DICOM (cine/video) - For whole-slide pathology images (SVS, NDPI), use `histolab-wsi-processing` instead - For NIfTI neuroimaging volumes (.nii/.nii.gz), use `nibabel` instead ## Prerequisites - **Python packages**: `py
- Overview
- When to Use
- Prerequisites
- Quick Start
- Core API
- Module 1: Reading and Metadata Access
- Module 2: Pixel Data Extraction
- Module 3: Image Conversion
- Module 4: Metadata Modification and Anonymization
- Module 5: Writing DICOM from Scratch
- Module 6: Series Processing and 3D Volumes
- Key Concepts
- DICOM Data Model
- Transfer Syntax and Compression
pip install pydicom numpy pillow pip install pylibjpeg pylibjpeg-libjpeg # JPEG Baseline/Lossless pip install pylibjpeg-openjpeg # JPEG 2000 pip install python-gdcm # Comprehensive codec support
What does the pydicom-medical-imaging skill do?
Pure Python DICOM for medical imaging (CT, MRI, X-ray, ultrasound). Read/write DICOM, pixels as NumPy, edit tags, windowing (VOI LUT), PHI anonymization, build DICOM, series→3D volumes. Use histolab for WSI pathology; nibabel for NIfTI.
How do I install it?
Run `npx skills add BioTender-max/awesome-bio-agent-skills --skill pydicom-medical-imaging --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From BioTender-max/awesome-bio-agent-skills, a repository with 135 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
