A wrapper for loading medical 2D, 3D, and 4D image volumes via multiple backends.
Project description
MedVol
medvol is a small wrapper around SimpleITK, nibabel, and pynrrd that
provides one interface for reading and writing 2D, 3D, and 4D NIfTI and NRRD
images.
Features
- One
MedVolAPI acrossSimpleITK,nibabel, andpynrrd - Automatic backend selection by extension
- NIfTI defaults to
nibabel - NRRD defaults to
pynrrd
- NIfTI defaults to
- Explicit backend override with
backend=... - Canonical
RAS+orientation by default across backends withcanonicalize=True - Optional geometry-only deobliquing with
remove_obliqueness=True affineas the single source of truth- Derived geometry properties:
spacingorigindirectiontranslationrotationscaleshearcoordinate_system
- Raw backend-native header access via
header
Installation
pip install medvol
Example
from medvol import MedVol
# Uses the bundled 3D NIfTI example.
image = MedVol("examples/data/3d_img.nii.gz")
print("Backend:", image.backend)
print("Shape:", image.array.shape)
print("Coordinate system:", image.coordinate_system)
print("Spacing:", image.spacing)
print("Origin:", image.origin)
print("Direction:\n", image.direction)
print("Affine:\n", image.affine)
print("Rotation:\n", image.rotation)
print("Header type:", type(image.header).__name__)
print("Center voxel:", image.array[tuple(size // 2 for size in image.array.shape)])
# Opt out of canonicalization to inspect backend-native geometry.
native_image = MedVol("examples/data/3d_img.nii.gz", backend="simpleitk", canonicalize=False)
print("Native coordinate system:", native_image.coordinate_system)
See example_showcase_3d_nifti.py for a runnable version.
Notes
- By default, MedVol canonicalizes loaded images to the closest array-aligned
RAS+orientation without interpolating voxel values. - Use
canonicalize=Falseto preserve backend-native array order and geometry. - Use
remove_obliqueness=Truetogether with canonicalization to strip obliqueness from the affine while leaving voxel values untouched. - For 4D NIfTI,
nibabeland theSimpleITKNIfTI path only support block-separable affines where the spatial axes do not couple to the 4th axis. Unsupported 5x5 affines raise aValueError.
Development
Run the test suite with:
pytest -q
License
Distributed under the terms of the Apache Software License 2.0.
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.21.tar.gz.
File metadata
- Download URL: medvol-0.0.21.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c53f1dcd60ac6a8cf98bf3a8f37e430aca42b899828cfd3acc5f9e8ece3b0f2f
|
|
| MD5 |
8f996aba712aeed784f2b948f80deb7c
|
|
| BLAKE2b-256 |
0a32c7b9d40c5fff63a3a0a957eee388f619a4e677c3b72da0edf1939dd99265
|
File details
Details for the file medvol-0.0.21-py3-none-any.whl.
File metadata
- Download URL: medvol-0.0.21-py3-none-any.whl
- Upload date:
- Size: 21.2 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 |
870a85922662e078221acd0b33b9729ded57a5caf7b8c8b93942960b4fe712c3
|
|
| MD5 |
e197367273a1a783beaa616d4fe9c14f
|
|
| BLAKE2b-256 |
fe1b8469a78a66f98e36b7c1fdd61e091b3aa89c5d3917658941ea9637497489
|