diff --git a/mu_map/util.py b/mu_map/util.py
index 259a7bbb970f2b2aa8132355f8eb367664d8adb4..914793b49953f190912a5456a0e9207945711c6b 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))