def to_image_color(img: Image, target_mode: str):
    """
    convert images from one color-space to another, like BGR ↔ Gray, BGR ↔ HSV, etc.
    """
    # pylint: disable=import-outside-toplevel
    from towhee.utils.cv2_utils import cv2
    if not hasattr(img, 'mode'):
        return img
    if img.mode == target_mode:
        return img

    flag_name = 'COLOR_' + img.mode.upper() + '2' + target_mode.upper()
    flag = getattr(cv2, flag_name, None)

    if flag is None:
        raise ValueError('Can not convert image from %s to %s.' % (img.mode, target_mode))

    return Image(cv2.cvtColor(img, flag), target_mode.upper())
convert images from one color-space to another, like BGR ↔ Gray, BGR ↔ HSV, etc.
towhee/types/image_utils.py