agentleFS
tondevreltondevrel/scientific-agent-skills/skills/pydicom/SKILL.md

pydicom

Skill23 starsChanged 10 months agoMITView on GitHub

Python package for working with DICOM files. It allows you to read, modify, and write DICOM data in a Pythonic way. Essential for medical imaging processing, clinical data extraction, and AI in radiology.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use pixel_array property: - Always access pixel data via ds.pixel_array rather than ds.PixelData for proper NumPy integration.

    line 66
  2. Very specific:

    Check for missing tags: - Use hasattr(ds, 'TagName') before accessing optional tags.

    line 67
  3. Distinctive:

    Don't modify DICOM files in place: - Always create a copy when modifying to preserve original data.

    line 73

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pydicom - Medical Imaging Standards

DICOM is more than an image; it's a rich data structure containing patient info, spatial orientation, and pixel data. Pydicom provides access to all these tags.

When to Use

  • Processing medical imaging data (CT, MRI, X-ray, ultrasound).
  • Extracting patient metadata and clinical information from DICOM files.
  • Building AI models for radiology that require both image and metadata.
  • Converting DICOM to other formats for analysis.
  • Quality assurance and compliance checking in medical imaging workflows.

Core Principles

Datasets as Dicts

Access tags by name (e.g., ds.PatientName) or ID (ds[0x0010, 0x0010]).

Pixel Data

Raw pixel data is stored in PixelData, but should be accessed via pixel_array for NumPy integration.

VR (Value Representation)

Strict typing for dates, ages, and decimals ensures data integrity.

Quick Reference

Standard Imports

import pydicom
from pydicom.data import get_testdata_files
import matplotlib.pyplot as plt
import numpy as np

Basic Patterns

# 1. Read file
ds = pydicom.dcmread("scan.dcm")

# 2. Access Metadata
print(f"Patient: {ds.PatientName}, ID: {ds.PatientID}")
print(f"Modality: {ds.Modality}") # CT, MR, DX
print(f"Study Date: {ds.StudyDate}")
print(f"Slice Thickness: {ds.SliceThickness}")

# 3. Access Image
plt.imshow(ds.pixel_array, cmap="gray")
plt.title(f"{ds.Modality} - {ds.PatientName}")

Critical Rules

✅ DO

  • Use pixel_array property - Always access pixel data via ds.pixel_array rather than ds.PixelData for proper NumPy integration.
  • Check for missing tags - Use hasattr(ds, 'TagName') before accessing optional tags.
  • Respect patient privacy - DICOM files contain PHI (Protected Health Information). Always anonymize before sharing.
  • Handle different photometric interpretations - Some images may be inverted or use different color spaces.

❌ DON'T

  • Don't modify DICOM files in place - Always create a copy when modifying to preserve original data.
  • Don't ignore VR types - DICOM has strict data types. Converting incorrectly can corrupt data.
  • Don't assume all DICOM files have images - Some contain only metadata (structured reports).

Advanced Patterns

Working with DICOM Series

import pydicom
from pathlib import Path

# Load a series of DICOM files
dicom_dir = Path("dicom_series")
files = sorted(dicom_dir.glob("*.dcm"))

# Load and stack slices
slices = [pydicom.dcmread(f) for f in files]
volume = np.stack([s.pixel_array for s in slices])

Anonymization

# Remove patient identifiers
ds.PatientName = "ANONYMOUS"
ds.PatientID = "000000"
ds.PatientBirthDate = ""
ds.PatientSex = ""

Pydicom is the foundation of medical imaging in Python, enabling researchers and clinicians to work with the rich, standardized DICOM format that powers modern radiology.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.