Skip to content

Commit

Permalink
Fix image read
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya-mohammadi committed Jan 27, 2024
1 parent d410e22 commit 7d0755c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion deep_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils.lib_utils.integeration_utils import import_lazy_module

# Deep Utils version number
__version__ = "1.3.15"
__version__ = "1.3.16"

from .utils.constants import DUMMY_PATH, Backends

Expand Down
23 changes: 13 additions & 10 deletions deep_utils/medical/sitk_utils/sitk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@

class SITKUtils:
@staticmethod
def get_array_img(sample_path: str, just_array: bool = False, just_sitk_img: bool = False) -> Union[
Image, np.ndarray, Tuple[np.ndarray, Image]]:
def get_array(sample_path: str) -> np.ndarray:
image = sitk.ReadImage(sample_path)
array = sitk.GetArrayFromImage(image)
if just_array and just_sitk_img:
raise ValueError("Both just keywords cannot be set to True!")
if just_array:
return array
if just_sitk_img:
return image
return array

return array, image
@staticmethod
def get_img(sample_path: str) -> Image:
image = sitk.ReadImage(sample_path)
return image

@staticmethod
def get_array_img(sample_path: str) -> Tuple[np.ndarray, Image]:
image = sitk.ReadImage(sample_path)
arr = sitk.GetArrayFromImage(image)
return arr, image

@staticmethod
def swap_seg_value(input_array: np.ndarray, swap_seg: Dict[int, int], max_val: int = 256) -> np.ndarray:
Expand Down Expand Up @@ -115,7 +118,7 @@ def save_sample(input_sample, org_sitk_img, save_path: str, time_array_index=-1,
org_direction = org_direction.reshape(3, 3)
org_direction = np.pad(org_direction, [(0, 1), (0, 1)], mode='constant', constant_values=1).flatten()
if org_direction.size == 25:
org_direction = org_direction.reshape((5,5))
org_direction = org_direction.reshape((5, 5))
if remove_index is None:
raise ValueError("remove index should be provided for 5,5 samples")
org_direction = np.delete(org_direction, remove_index, 0)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.3.15"
VERSION = "1.3.16"

long_description = open("Readme.md", mode="r", encoding="utf-8").read()

Expand Down

0 comments on commit 7d0755c

Please sign in to comment.