From f08f9c8438eb900d2651039f1102daf9e147c580 Mon Sep 17 00:00:00 2001 From: Tamino Huxohl <thuxohl@techfak.uni-bielefeld.de> Date: Fri, 2 Sep 2022 13:23:01 +0200 Subject: [PATCH] fix to rgb method and support converting empty images to grayscale --- mu_map/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mu_map/util.py b/mu_map/util.py index 259a7bb..914793b 100644 --- a/mu_map/util.py +++ b/mu_map/util.py @@ -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)) -- GitLab