Skip to content

Commit

Permalink
MAINT: Make sure to clip image before converting to ubyte
Browse files Browse the repository at this point in the history
  • Loading branch information
jwboth committed Jun 16, 2024
1 parent 5e81581 commit b9d04f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/darsia/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ def img_as(self, data_type) -> Any:
"""
copy_image = self.copy()
dtype = copy_image.img.dtype
is_float = dtype in [float, np.float16, np.float32, np.float64]
if data_type in [bool]:
copy_image.img = skimage.img_as_bool(copy_image.img)
elif data_type in [float]:
Expand All @@ -499,7 +501,9 @@ def img_as(self, data_type) -> Any:
elif data_type in [int]:
copy_image.img = skimage.img_as_int(copy_image.img)
elif data_type in [np.uint8]:
copy_image.img = skimage.img_as_ubyte(copy_image.img)
copy_image.img = skimage.img_as_ubyte(
np.clip(copy_image.img, -1, 1) if is_float else copy_image.img
)
elif data_type in [np.uint16]:
copy_image.img = skimage.img_as_uint(copy_image.img)
else:
Expand Down

0 comments on commit b9d04f3

Please sign in to comment.