Skip to main content

A tool for checking DICOM compliance against a template

Project description

dicompare

dicompare is a DICOM validation tool designed to ensure compliance with study-specific imaging protocols and domain-specific guidelines while preserving data privacy. It provides multiple interfaces, including support for validation directly in the browser at dicompare.neurodesk.org, leveraging WebAssembly (WASM), Pyodide, and the underlying pip package dicompare. dicompare is suitable for multi-site studies and clinical environments without requiring software installation or external data uploads.

dicompare supports DICOM session validation against templates based on:

  • Reference sessions: JSON schema files can be generated based on a reference MRI scanning session;
  • Domain guidelines: Flexible guidelines for specific domains (e.g. QSM, ASL, MS/CMSC);
  • Landmark studies: A bundled schema library includes protocols from HCP, ABCD, UK Biobank, and more.

Command-line interface (CLI) and application programming interface (API)

While you can run dicompare in your browser now without any installation, you may also use the underlying dicompare pip package if you wish to use the command-line interface (CLI) or application programming interface (API).

pip install dicompare

Command-line interface (CLI)

The package provides a unified dicompare command with three subcommands:

  • dicompare build: Generate a JSON schema from a reference DICOM session
  • dicompare check: Validate DICOM sessions against a JSON schema
  • dicompare match: Find best-matching schemas for input DICOM data from a library

1. Build a JSON schema from a reference session

dicompare build /path/to/dicom/session schema.json

This creates a JSON schema describing the session based on default reference fields present in the data.

2. Check a DICOM session against a schema

dicompare check /path/to/dicom/session schema.json

The tool will output an acquisition mapping summary with confidence scores, followed by a compliance report indicating deviations from the schema. Use --auto-yes or -y to skip interactive mapping prompts:

dicompare check /path/to/dicom/session schema.json --auto-yes

Save the compliance report to a JSON file by specifying a report path:

dicompare check /path/to/dicom/session schema.json compliance_report.json

3. Find best-matching schemas for your data

Search across a schema library to identify which protocols best match your DICOM data:

# Search the bundled schema library
dicompare match /path/to/dicom/session --library

# Search custom schema files or directories
dicompare match /path/to/dicom/session --schemas /path/to/schemas/

# Combine bundled library and custom schemas
dicompare match /path/to/dicom/session --library --schemas /path/to/custom_schema.json

This compares each input acquisition against every acquisition in the loaded schemas, ranking matches by compliance score. Options:

  • --library: Include the bundled schema library (HCP, ABCD, UK Biobank, and more)
  • --schemas PATH [PATH ...]: Path(s) to schema files or directories containing schemas
  • --top N: Number of top matches to show per acquisition (default: 5)
  • --report PATH: Save the match report to a JSON file

Python API

The dicompare package provides a comprehensive Python API for programmatic schema generation, validation, and DICOM processing.

Loading DICOM data

Load a DICOM session:

from dicompare import load_dicom_session

session_df = load_dicom_session(
    session_dir="/path/to/dicom/session",
    show_progress=True
)

Load individual DICOM files:

from dicompare import load_dicom

dicom_data = load_dicom(
    dicom_paths=["/path/to/file1.dcm", "/path/to/file2.dcm"],
    show_progress=True
)

Load Siemens .pro files:

from dicompare import load_pro_session

pro_session = load_pro_session(
    session_dir="/path/to/pro/files",
    show_progress=True
)

Build a JSON schema

from dicompare import load_dicom_session, build_schema, make_json_serializable
from dicompare.config import DEFAULT_SETTINGS_FIELDS
import json

# Load the reference session
session_df = load_dicom_session(
    session_dir="/path/to/dicom/session",
    show_progress=True
)

# Build the schema
json_schema = build_schema(session_df)

# Save the schema
serializable_schema = make_json_serializable(json_schema)
with open("schema.json", "w") as f:
    json.dump(serializable_schema, f, indent=4)

Validate a session against a JSON schema

from dicompare import (
    load_schema,
    load_dicom_session,
    check_acquisition_compliance,
    map_to_json_reference,
    assign_acquisition_and_run_numbers
)

# Load the JSON schema
reference_fields, json_schema, validation_rules = load_schema(json_schema_path="schema.json")

# Load the input session
in_session = load_dicom_session(
    session_dir="/path/to/dicom/session",
    show_progress=True
)

# Assign acquisition and run numbers
in_session = assign_acquisition_and_run_numbers(in_session)

# Map acquisitions to schema
session_map = map_to_json_reference(in_session, json_schema)

# Check compliance for each acquisition
compliance_summary = []
for ref_acq_name, schema_acq in json_schema["acquisitions"].items():
    if ref_acq_name not in session_map:
        continue

    input_acq_name = session_map[ref_acq_name]
    acq_validation_rules = validation_rules.get(ref_acq_name) if validation_rules else None

    results = check_acquisition_compliance(
        in_session,
        schema_acq,
        acquisition_name=input_acq_name,
        validation_rules=acq_validation_rules
    )
    compliance_summary.extend(results)

# Display results
for entry in compliance_summary:
    print(entry)

Additional utilities

Assign acquisition and run numbers:

from dicompare import assign_acquisition_and_run_numbers

session_df = assign_acquisition_and_run_numbers(session_df)

Get DICOM tag information:

from dicompare import get_tag_info, get_all_tags_in_dataset

# Get info about a specific tag
tag_info = get_tag_info("EchoTime")
print(tag_info)  # {'tag': '(0018,0081)', 'name': 'Echo Time', 'type': 'float'}

# Get all tags in a dataset
all_tags = get_all_tags_in_dataset(dicom_metadata)

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

dicompare-0.2.0.tar.gz (234.5 kB view details)

Uploaded Source

Built Distribution

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

dicompare-0.2.0-py3-none-any.whl (266.0 kB view details)

Uploaded Python 3

File details

Details for the file dicompare-0.2.0.tar.gz.

File metadata

  • Download URL: dicompare-0.2.0.tar.gz
  • Upload date:
  • Size: 234.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for dicompare-0.2.0.tar.gz
Algorithm Hash digest
SHA256 05d19afb25496e0ea9c1b46ff56cb6f2daecdc1a77212c3ce244276acd6fd7e2
MD5 e8b8895cb6b66ce51031c581678c47d0
BLAKE2b-256 7b274b1583fe7a1a03fb51c71214e743a7037dbd7c74c8a1f8e5dd374089da9e

See more details on using hashes here.

File details

Details for the file dicompare-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dicompare-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 266.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for dicompare-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9fa49aa01471c0c7f891943a570297969619ef7818668b83a83e11c0b68a9c1
MD5 1e2c9bdb0d9fe96ec64677fdedec39e1
BLAKE2b-256 c3a035c5cdf963f6e0bb48ab40060496119ee79f1033e53ca27ab57ada2605b4

See more details on using hashes here.

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