Exemplo n.º 1
0
def rgb2luv(image, un=0.2009, vn=0.4610):
    """
    Converts an RGB image into an LUV

    params
    -------
        image: ndarray (X, Y, 3)
    """

    Yn = rgb2xyz(np.ones((1, 1, 3)).astype(float))[0][0][2]
    image_xyz = rgb2xyz(image)
    image_luv = np.zeros(image.shape)
    u = 4 * image_xyz[:, :, 0] / (image_xyz[:, :, 0] + 15 * image_xyz[:, :, 1] + 3 * image_xyz[:, :, 2])
    v = 9 * image_xyz[:, :, 1] / (image_xyz[:, :, 1] + 15 * image_xyz[:, :, 1] + 3 * image_xyz[:, :, 2])

    calc = image[:, :, 1] / Yn <= (6.0 / 29) ** 3
    image_luv[calc, :, 0] = (29.0 / 3) ** 3 * image_xyz[calc, :, 1] / Yn
    calc = image[:, :, 1] / Yn > (6.0 / 29) ** 3
    image_luv[calc, :, 0] = 116 * image_xyz[calc, :, 1] ** (-1.0 / 3) / Yn

    image_luv[:, :, 1] = 13 * image_luv[:, :, 0] * (u - un)
    image_luv[:, :, 2] = 13 * image_luv[:, :, 0] * (v - vn)
    return image_luv
Exemplo n.º 2
0
def luv2rgb(image, un=0.2009, vn=0.4610):
    """
    Convers an LUV image to RGB

    params:
        image: ndarray (X, Y, 3)
    """
    image_xyz = np.zeros(image.shape)
    Yn = rgb2xyz(np.ones((1, 1, 3)).astype(float))[0][0][2]
    calc = image[:, :, 0] <= 8
    image_xyz[calc, :, 1] = Yn * image[calc, :, 0] * (3.0 / 29) ** 3
    calc = image[:, :, 0] > 8
    image_xyz[calc, :, 1] = Yn * ((image[calc, :, 0] + 16.0) / 116) ** 3

    u = image[:, :, 1] / (13 * image[:, :, 0]) + un
    v = image[:, :, 2] / (13 * image[:, :, 0]) + un

    image_xyz[:, :, 0] = image_xyz[:, :, 1] * 9 * u / v
    image_xyz[:, :, 2] = (12 - 3 * u - 20 * v) / (4 * v)
    return xyz2rgb(image_xyz)