Skip to content
Snippets Groups Projects
Commit f08f9c84 authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

fix to rgb method and support converting empty images to grayscale

parent c72ccd7d
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,9 @@ def to_grayscale(
if max_val is None:
max_val = img.max()
if (max_val - min_val) == 0:
return np.zeros(img.shape, np.uint8)
_img = (img - min_val) / (max_val - min_val)
_img = (_img * 255).astype(np.uint8)
return _img
......@@ -36,4 +39,4 @@ def grayscale_to_rgb(img: np.ndarray):
:return: the image in rgb
"""
assert img.ndim == 2, f"grascale image has more than 2 dimensions {img.shape}"
return img.repeat(3).reshape((3, *img.shape))
return img.repeat(3).reshape((*img.shape, 3))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment