diff --git a/medvol/__init__.py b/medvol/__init__.py index 8e52f49..057aa2e 100644 --- a/medvol/__init__.py +++ b/medvol/__init__.py @@ -1,3 +1,3 @@ -__version__ = "0.0.11" +__version__ = "0.0.12" from medvol.medvol import MedVol \ No newline at end of file diff --git a/medvol/medvol.py b/medvol/medvol.py index c832efe..1ee2426 100644 --- a/medvol/medvol.py +++ b/medvol/medvol.py @@ -1,6 +1,7 @@ import SimpleITK as sitk from typing import Dict, Optional, Union, List, Tuple import numpy as np +from pathlib import Path # TODO: # - Enable user to set affine @@ -23,7 +24,7 @@ def __init__(self, is_seg: Optional[bool] = None, copy: Optional['MedVol'] = None) -> None: # Validate array: Must be a 2D, 3D or 4D array - if not ((isinstance(array, np.ndarray) and (array.ndim == 2 or array.ndim == 3 or array.ndim == 4)) or isinstance(array, str)): + if not ((isinstance(array, np.ndarray) and (array.ndim == 2 or array.ndim == 3 or array.ndim == 4)) or isinstance(array, (str, Path))): raise ValueError("Array must be a 2D, 3D or 4D numpy array or a filepath string.") elif isinstance(array, str) and (spacing is not None or origin is not None or direction is not None or header is not None or is_seg is not None or copy is not None): raise RuntimeError("Spacing, origin, direction, header, is_seg or copy cannot be set if array is a string to load an image.") @@ -129,7 +130,7 @@ def _copy_fields_from(self, other: 'MedVol'): self.is_seg = other.is_seg def _load(self, filepath): - image_sitk = sitk.ReadImage(filepath) + image_sitk = sitk.ReadImage(str(filepath)) array = sitk.GetArrayFromImage(image_sitk) ndims = len(array.shape) metadata_ndims = len(image_sitk.GetSpacing()) @@ -170,4 +171,4 @@ def save(self, filepath): if self.header is not None: for key, value in self.header.items(): image_sitk.SetMetaData(key, value) - sitk.WriteImage(image_sitk, filepath, useCompression=True) \ No newline at end of file + sitk.WriteImage(image_sitk, str(filepath), useCompression=True) \ No newline at end of file