A wrapper for loading medical 2D, 3D, and 4D image volumes via multiple backends.
Project description
MedVol
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
MedVolclass works with all three back‑ends. - Automatic backend selection based on file extension:
.nii/.nii.gz→nibabel.nrrd→pynrrd
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04c7a808d21f9538bd27707d483315996d1aa7604fc46c751c45638812723c1e
|
|
| MD5 |
b4033cbbf6dc995228b5e82d4923303c
|
|
| BLAKE2b-256 |
7f7d47b1625efb91fa178a394e6d6c4b9c7c3a01cccd99a59d8e523d02cfe896
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03d9670b6cffa75ccbc6307aaf1a8397ad8363626a4cae95c2bd3e1732a0a564
|
|
| MD5 |
4e5c69af7d80c681724bd436a5d2c841
|
|
| BLAKE2b-256 |
b32df11099473dbae7adde9ee4df6fcf91b339b019561ffaecc3de76b33c47f6
|