Skip to main content

A wrapper for loading medical 2D, 3D, and 4D image volumes via multiple backends.

Project description

MedVol

PyPI version Python versions Build status License

A lightweight Python wrapper that unifies SimpleITK, nibabel, and pynrrd under a single, simple API for reading and writing 2‑D, 3‑D, and 4‑D medical images in NIfTI (.nii/.nii.gz) and NRRD (.nrrd) formats.

✨ Features

  • Unified API – one MedVol class works with all three back‑ends.
  • Automatic backend selection based on file extension:
    • .nii/.nii.gznibabel
    • .nrrdpynrrd
  • Explicit backend override via the backend= argument.
  • Canonical RAS+ orientation by default (no interpolation).
  • Optional de‑obliquing via get_geometry(deoblique=True).
  • Geometry is stored in a single source of truth – the affine matrix.
  • Convenient derived properties: spacing, origin, direction, rotation, shear, coordinate_system.
  • Direct access to the raw backend header through header.

📦 Installation

pip install medvol

🚀 Quick start

from medvol import MedVol

# Load the bundled 3‑D example image (NIfTI).
img = MedVol("examples/data/3d_img.nii.gz")

print("Backend:", img.backend)
print("Shape:", img.array.shape)
print("Coordinate system:", img.coordinate_system)
print("Spacing:", img.spacing)
print("Origin:", img.origin)
print("Direction:\n", img.direction)
print("Affine:\n", img.affine)
print("Rotation:\n", img.rotation)
print("Header type:", type(img.header).__name__)

# Access the centre voxel value.
center = tuple(s // 2 for s in img.array.shape)
print("Center voxel:", img.array[center])

To inspect the native geometry without canonicalisation:

native = MedVol(
    "examples/data/3d_img.nii.gz",
    backend="simpleitk",
    canonicalize=False,
)
print("Native coordinate system:", native.coordinate_system)

See the runnable demo at examples/example_showcase_3d_nifti.py.

Contributing

Contributions are welcome! Please open a pull request with clear changes and add tests when appropriate.

Acknowledgments

    

This repository is developed and maintained by the Applied Computer Vision Lab (ACVL) of Helmholtz Imaging and the Division of Medical Image Computing at DKFZ.

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

medvol-0.0.22.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

medvol-0.0.22-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file medvol-0.0.22.tar.gz.

File metadata

  • Download URL: medvol-0.0.22.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for medvol-0.0.22.tar.gz
Algorithm Hash digest
SHA256 04c7a808d21f9538bd27707d483315996d1aa7604fc46c751c45638812723c1e
MD5 b4033cbbf6dc995228b5e82d4923303c
BLAKE2b-256 7f7d47b1625efb91fa178a394e6d6c4b9c7c3a01cccd99a59d8e523d02cfe896

See more details on using hashes here.

File details

Details for the file medvol-0.0.22-py3-none-any.whl.

File metadata

  • Download URL: medvol-0.0.22-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for medvol-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 03d9670b6cffa75ccbc6307aaf1a8397ad8363626a4cae95c2bd3e1732a0a564
MD5 4e5c69af7d80c681724bd436a5d2c841
BLAKE2b-256 b32df11099473dbae7adde9ee4df6fcf91b339b019561ffaecc3de76b33c47f6

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