A wrapper for loading medical 2D, 3D and 4D NIFTI or NRRD images.
Features:
- Supports loading and saving of 2D, 3D and 4D Nifti and NRRD images
- (Saving 4D images is currently not supported due to a SimpleITK bug)
- Simple access to image array
- Simple access to image metadata
- Affine
- Spacing
- Origin
- Direction
- Translation
- Rotation
- Scale (Same as spacing)
- Shear
- Header (The raw header)
- Copying/Modification of all or selected metadata across MedVol images
You can install medvol
via pip:
pip install medvol
from medvol import MedVol
# Load NIFTI image
image = MedVol("path/to/image.nifti")
# Print some metadata
print("Spacing: ", image.spacing)
print("Affine: ", image.affine)
print("Rotation: ", image.rotation)
print("Header: ", image.header)
# Access and modify the image array
arr = image.array
arr[0, 0, 0] = 1
# Create a new image with the new array, a new spacing, but copy all remaining metadata
new_image = MedVol(arr, spacing=[2, 2, 2], copy=image)
# Save the new image as NRRD
new_image.save("path/to/new_image.nrrd")
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the Apache Software License 2.0 license, "medvol" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.