Skip to main content

A tool to convert DICOM cine movies to GIF format (and others).

Project description

dicom2gif

A Python tool to convert DICOMs of MRI cine series to GIF/APNG/TIFF format.

Features

  • Convert enhanced DICOM files (multi-frame) to GIF, APNG, or TIFF
  • Convert legacy DICOM series to GIF, APNG, or TIFF
  • Automatic detection of frame duration from DICOM metadata
  • Support for windowing (brightness/contrast) adjustment
  • Batch processing of entire directories

Installation

pip install dicom2gif

Usage

Command Line

After installation, you can use the tool in three ways:

# As an installed script
dicom2gif path/to/dicom/file.dcm

# Using python -m
python -m dicom2gif path/to/dicom/file.dcm

# With custom output and duration
dicom2gif input.dcm -o output.gif -d 100

Command Line Options

  • dcm_path: Input DICOM file or directory
  • -p, --pattern: Pattern to select DICOM files when dcm_path is a directory (defaults to *.dcm)
  • -o, --out_file: Output file path (defaults to input name with .gif extension)
  • -f, --format: Output file format, can be gif, apng, or tiff/tif (ignored if --out_file is given)
  • -d, --duration: Duration per frame in milliseconds (optional, auto-detected from DICOM if available)
  • -w, --windowing: Can be two comma-separated integers for window center and width, 'auto' for automatic windowing to full dynamic range, or None to use windowing parameters from DICOM metadata (defaults to None)

Process a Directory

When given a directory, the tool will recursively:

  • Create a separate GIF for each enhanced DICOM file
  • Create a separate GIF for each series of legacy DICOM files as determined by their Series Instance UID
dicom2gif path/to/dicom/directory

Python API

from dicom2gif import dicom2gif, read_dcm, read_dir, write_gif

# Single DICOM file
cine = read_dcm("path/to/file.dcm")
write_gif(cine, "output.gif", duration=50)

# Directory of DICOM files
cines = read_dir("path/to/directory")
for path, cine in cines:
    out_file = path.with_suffix(".apng")
    write_gif(cine, out_file, windowing="auto")

# Or directly
dicom2gif("path/to/file.dcm", out_file="output.gif", duration=50)
dicom2gif("path/to/directory", format="apng", windowing="auto")

Requirements

  • Python ≥ 3.10
  • numpy
  • Pillow ≥ 7.1.2
  • pydicom

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dicom2gif-0.0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dicom2gif-0.0.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dicom2gif-0.0.1.tar.gz.

File metadata

  • Download URL: dicom2gif-0.0.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dicom2gif-0.0.1.tar.gz
Algorithm Hash digest
SHA256 384a9fffbf6bcdcdb7ff27010333a3e654163ab742dc3532d0a9e2e27d930ce4
MD5 6eda78a53204ead8ce3ca3c6fa54069a
BLAKE2b-256 0425573d357975838bc2cbcff595f8ebb0a7c757ed3dd208ee1c8c37c8854ddd

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicom2gif-0.0.1.tar.gz:

Publisher: publish-to-pypi.yml on marcvornehm/dicom2gif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dicom2gif-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dicom2gif-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dicom2gif-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd56f434fda9325715b67648c808222902e6b6a7f178b0a1be10d2773f1ba829
MD5 bf07210e7072f236474f71c841ecbb78
BLAKE2b-256 17d84ddbc32a79960bc9c4d8305e4d68c2670410777bb4322f570e8f8b453ff8

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicom2gif-0.0.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on marcvornehm/dicom2gif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page