diff --git a/mu_map/util.py b/mu_map/util.py index a2637bed3268385e0e7dc4dc0d70223cce3e5516..259a7bbb970f2b2aa8132355f8eb367664d8adb4 100644 --- a/mu_map/util.py +++ b/mu_map/util.py @@ -26,3 +26,14 @@ def to_grayscale( _img = (img - min_val) / (max_val - min_val) _img = (_img * 255).astype(np.uint8) return _img + + +def grayscale_to_rgb(img: np.ndarray): + """ + Convert a grayscale image to an rgb image by repeating it three times. + + :param img: the grayscale image to be converted to rgb + :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))