image.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:tensorlight 作者: bsautermeister 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号