Skip to content

Commit

Permalink
doc: Updated README & docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol-G committed Aug 20, 2024
1 parent 92d21da commit 3ac8db2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

A wrapper for loading medical 3D image volumes such as 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


## Installation

You can install `medvol` via [pip](https://pypi.org/project/medvol/):
Expand All @@ -23,6 +40,7 @@ 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
Expand Down
15 changes: 2 additions & 13 deletions medvol/medvol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
# TODO:
# - Enable user to set affine
# - Reflect changes in affine in all other parameters
# - Add affine_3d function?
# - Create docstrings and docs
# - Create docs
# - Write tests
# - Rename into MedImg
# - Fix is_seg
# - Fix napari-nifti loading of 2D and 4D images


class MedVol:
Expand Down Expand Up @@ -122,13 +120,7 @@ def affine(self) -> np.ndarray:
Returns:
np.ndarray: The affine matrix representing the translation, scaling, and rotation of the image.
Raises:
ValueError: If spacing, origin, or direction are not set.
"""
if self.spacing is None or self.origin is None or self.direction is None:
raise ValueError("Spacing, origin, and direction must all be set to compute the affine.")

"""
affine = np.eye(self.ndims+1)
affine[:self.ndims, :self.ndims] = self.direction @ np.diag(self.spacing)
affine[:self.ndims, self.ndims] = self.origin
Expand Down Expand Up @@ -186,9 +178,6 @@ def ndims(self) -> int:
Returns:
int: The number of dimensions of the image (2D, 3D, or 4D).
Raises:
ValueError: If the array is not set.
"""
return len(self.array.shape)

Expand Down

0 comments on commit 3ac8db2

Please sign in to comment.