Skip to main content

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 MedVol API across SimpleITK, nibabel, and pynrrd
  • Automatic backend selection by extension
    • NIfTI defaults to nibabel
    • NRRD defaults to pynrrd
  • Explicit backend override with backend=...
  • Canonical RAS+ orientation by default across backends with canonicalize=True
  • Optional geometry-only deobliquing with remove_obliqueness=True
  • affine as the single source of truth
  • Derived geometry properties:
    • spacing
    • origin
    • direction
    • translation
    • rotation
    • scale
    • shear
    • coordinate_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=False to preserve backend-native array order and geometry.
  • Use remove_obliqueness=True together with canonicalization to strip obliqueness from the affine while leaving voxel values untouched.
  • For 4D NIfTI, nibabel and the SimpleITK NIfTI path only support block-separable affines where the spatial axes do not couple to the 4th axis. Unsupported 5x5 affines raise a ValueError.

Development

Run the test suite with:

pytest -q

License

Distributed under the terms of the Apache Software License 2.0.

Metadata

Release files for medvol 0.0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medvol 0.0.21
File Size Uploaded Provenance Actions
medvol-0.0.21.tar.gz 21.1 kB Without provenance Details for medvol-0.0.21.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for medvol 0.0.21
File Interpreter ABI Platform Actions
medvol-0.0.21-py3-none-any.whl Python 3 none any Details for medvol-0.0.21-py3-none-any.whl

Total release size: 42.3 kB

Release files / medvol-0.0.21.tar.gz

Download URL medvol-0.0.21.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c53f1dcd60ac6a8cf98bf3a8f37e430aca42b899828cfd3acc5f9e8ece3b0f2f
BLAKE2b-256 checksum
How to use checksums
0a32c7b9d40c5fff63a3a0a957eee388f619a4e677c3b72da0edf1939dd99265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / medvol-0.0.21-py3-none-any.whl

Download URL medvol-0.0.21-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
870a85922662e078221acd0b33b9729ded57a5caf7b8c8b93942960b4fe712c3
BLAKE2b-256 checksum
How to use checksums
fe1b8469a78a66f98e36b7c1fdd61e091b3aa89c5d3917658941ea9637497489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for medvol 0.0.21

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page