Skip to main content

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 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.

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.21.tar.gz (21.1 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.21-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

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

Hashes for medvol-0.0.21.tar.gz
Algorithm Hash digest
SHA256 c53f1dcd60ac6a8cf98bf3a8f37e430aca42b899828cfd3acc5f9e8ece3b0f2f
MD5 8f996aba712aeed784f2b948f80deb7c
BLAKE2b-256 0a32c7b9d40c5fff63a3a0a957eee388f619a4e677c3b72da0edf1939dd99265

See more details on using hashes here.

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

Hashes for medvol-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 870a85922662e078221acd0b33b9729ded57a5caf7b8c8b93942960b4fe712c3
MD5 e197367273a1a783beaa616d4fe9c14f
BLAKE2b-256 fe1b8469a78a66f98e36b7c1fdd61e091b3aa89c5d3917658941ea9637497489

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