Skip to main content

A tool to convert DICOM series to GIF/APNG/TIFF format.

Project description

dicom2gif

A Python tool to convert DICOM series to GIF/APNG/TIFF format

Features

  • Convert enhanced (multi-frame) and 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
  • Select range of frames to save
  • Per-file output mode (one output file per DICOM file)

Installation

pip install dicom2gif

Usage

Command Line

After installation, dicom2gif can be used as a command line tool. When given a directory, the tool will recursively search for DICOM files with the same Series Instance UID and create a separate movie file for each series.

dicom2gif [-h] [-p PATTERN] [-o OUT_FILE] [-f {gif,apng,tiff}] [-d DURATION] [-w WINDOWING] [--frames FRAMES] [--per-file] [-v] dcm_path

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 (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, 'dicom' for windowing parameters from DICOM metadata, or 'full' for windowing to full dynamic range (defaults to 'dicom')
  • --frames: Frame range (1-based, inclusive). Examples: '5' (frame 5 only), '10-20' (frames 10 to 20), '10-' (frame 10 to end), '-20' (start to frame 20).
  • --per-file: Produce one output file per input DICOM file instead of one per series. By default, all files sharing the same SeriesInstanceUID are merged into a single animated output. With --per-file, each DICOM file is converted independently.
  • -v, --verbose: Print debug information (windowing values, frame counts, pixel ranges, etc.).

Python API

from dicom2gif import dicom2gif, read_dcm, read_dir, write

# Single enhanced DICOM file
series = read_dcm("path/to/file.dcm")
write(series, "output.gif", duration=50)

# Directory of DICOM files
all_series = read_dir("path/to/directory")
for path, series in all_series.items():
    out_file = path.with_suffix(".apng")
    write(series, out_file, windowing="dicom")

# Or directly
dicom2gif("path/to/file.dcm", out_file="output.gif", duration=50)
dicom2gif("path/to/directory", format="apng", windowing="full", frame_start=2, frame_end=10)
dicom2gif("path/to/directory", per_file=True)  # one output per DICOM file

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-1.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

dicom2gif-1.2.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dicom2gif-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9d8a8022c331ea262f69f8299333759e30d91ede6ed302f93bd4f32213cb4db5
MD5 f414ec316e7b8c21666d6f649bcd5544
BLAKE2b-256 cc761d9e31d24286d582201e398891df3da1c349ac66bcbbd0ea16bdec5421c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicom2gif-1.2.0.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-1.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dicom2gif-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff9b299a2eb16ec299c4e5c47a00ec5d5c4c9ccc0d2e3e065b14768c822502e7
MD5 b38976802f527d8805ddb997f0b03bc4
BLAKE2b-256 f637e76c237cfc91747c3945781ed6e16ccd64f2218a2ee1dec3a58ec5b3330e

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicom2gif-1.2.0-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