def to_rgb(image):
"""Converts a grayscaled image to a colored one.
Parameters
----------
image: ndarray(uint8)
A grayscaled image with the shape of [height, width, 1]
or of shape [height, widht].
Returns
---------
image: ndarray(uint8)
Returns a converted image with shape [height, width, 3].
"""
image_shape = image.shape
if len(image_shape) > 2:
img_channels = image_shape[2]
if img_channels == 1:
image = np.squeeze(image, axis=2)
if img_channels != 3:
image = cast(image)
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
return image
评论列表
文章目录