DEV Community

Cover image for Stop writing ds[0x0010, 0x0010].value — there's a better way to handle DICOM in Python
Mustufa Merchant
Mustufa Merchant

Posted on

Stop writing ds[0x0010, 0x0010].value — there's a better way to handle DICOM in Python

Every Python DICOM tutorial starts the same way:

import pydicom
ds = pydicom.dcmread("scan.dcm")
print(ds[0x0010, 0x0010].value)  # patient name??
Enter fullscreen mode Exit fullscreen mode

You memorize hex pairs. You copy-paste anonymization tag lists from Stack Overflow. You write the same VOI windowing helper for the third time on a new project.

I got tired of it. So I built DICOMForge.

What it looks like instead

from dicomforge.api import DicomFile
f = DicomFile("scan.dcm")
print(f.patient_name, f.modality, f.slice_thickness)
Enter fullscreen mode Exit fullscreen mode

Named properties. No hex. No .value. Lazy-loaded.

Anonymize in one line

from dicomforge.api import quick_anonymize
quick_anonymize("scan.dcm", "anon.dcm", uid_salt="my-secret")
Enter fullscreen mode Exit fullscreen mode

Under the hood: 48 PS3.15 rules, deterministic UID remapping (same source UID always maps to the same output — referential integrity preserved), audit report available if you need it.

Display a CT slice with zero boilerplate

from dicomforge.adapt import to_pil_image
img = to_pil_image(dataset)  # VOI windowing + MONOCHROME1 inversion handled
img.save("output.png")
Enter fullscreen mode Exit fullscreen mode

Still on pydicom? Bridge in, bridge out

from dicomforge.adapt import from_pydicom, to_pydicom
ds = from_pydicom(your_existing_dataset)
# use dicomforge APIs
pydicom_ds = to_pydicom(ds)
Enter fullscreen mode Exit fullscreen mode

You don't have to rewrite anything.

Install

pip install dicomforge                # zero dependencies
pip install "dicomforge[pixels]"      # + numpy + pillow
pip install "dicomforge[all]"         # everything
Enter fullscreen mode Exit fullscreen mode

Zero core dependencies. Optional backends raise clear errors with exact install instructions — no silent import failures.

What it's not
Not a medical device. Not wire-compatible DIMSE. Not a pydicom replacement for edge-case VRs. The conformance docs are explicit about the boundaries.

v0.6.0, MIT licensed, 108 tests, stdlib only.

If you work with DICOM pipelines — what's the part you find most painful? Would love to know what to tackle next.

Top comments (0)