Beispiel #1
0
def XYZ_to_Luv(cobj, *args, **kwargs):
    """
    Convert from XYZ to Luv
    """
    temp_x = cobj.xyz_x
    temp_y = cobj.xyz_y
    temp_z = cobj.xyz_z
    denom = temp_x + (15.0 * temp_y) + (3.0 * temp_z)
    # avoid division by zero
    if denom == 0.0:
        luv_u = 0.0
        luv_v = 0.0
    else:
        luv_u = (4.0 * temp_x) / denom
        luv_v = (9.0 * temp_y) / denom

    illum = cobj.get_illuminant_xyz()
    temp_y = temp_y / illum["Y"]
    if temp_y > color_constants.CIE_E:
        temp_y = math.pow(temp_y, (1.0 / 3.0))
    else:
        temp_y = (7.787 * temp_y) + (16.0 / 116.0)

    ref_U = (4.0 * illum["X"]) / (illum["X"] + (15.0 * illum["Y"]) + (3.0 * illum["Z"]))
    ref_V = (9.0 * illum["Y"]) / (illum["X"] + (15.0 * illum["Y"]) + (3.0 * illum["Z"]))

    luv_l = (116.0 * temp_y) - 16.0
    luv_u = 13.0 * luv_l * (luv_u - ref_U)
    luv_v = 13.0 * luv_l * (luv_v - ref_V)

    return LuvColor(
        luv_l, luv_u, luv_v, observer=cobj.observer, illuminant=cobj.illuminant)
Beispiel #2
0
def LCHuv_to_Luv(cobj, *args, **kwargs):
    """
    Convert from LCH(uv) to Luv.
    """
    luv_l = cobj.lch_l
    luv_u = math.cos(math.radians(cobj.lch_h)) * cobj.lch_c
    luv_v = math.sin(math.radians(cobj.lch_h)) * cobj.lch_c
    return LuvColor(
        luv_l, luv_u, luv_v, illuminant=cobj.illuminant, observer=cobj.observer)
Beispiel #3
0
plt.imshow(value)
plt.colorbar()
plt.savefig('value.pdf', bbox_inches='tight')
plt.close()

plt.imshow(error)
plt.colorbar()
plt.savefig('error.pdf', bbox_inches='tight')
plt.close()

total = numpy.zeros((value.shape[0], value.shape[1], 3))

for i in range(len(x)):
    for j in range(len(y)):
        h = value[i, j] / 2 + 0.5
        h = math.fmod(h + 2, 1)
        #h = 0.25
        #v = 1 - h
        v = 0.
        l = error[i, j]**0.5
        l = max(min(l, 1), 0)
        rgb = convert_color(
            LuvColor(luv_l=l * 100, luv_u=h * 100, luv_v=v * 100), sRGBColor)
        #print(rgb.get_value_tuple())
        rgb = [rgb.clamped_rgb_r, rgb.clamped_rgb_g, rgb.clamped_rgb_b]
        total[i, j, :] = rgb

plt.imshow(total)
plt.savefig('lab.pdf', bbox_inches='tight')
plt.close()
Beispiel #4
0
def luv_to_rgb(luv):
    luvcolor = LuvColor(*luv)
    rgbcolor = luvcolor.convert_to('rgb')
    return (rgbcolor.rgb_r, rgbcolor.rgb_g, rgbcolor.rgb_b)
Beispiel #5
0
 def test_conversion_to_luv(self):
     luv = convert_color(self.color, LuvColor)
     self.assertColorMatch(luv, LuvColor(1.807, -2.564, -0.894))
Beispiel #6
0
 def setUp(self):
     self.color = LuvColor(1.807, -2.564, -0.894)
Beispiel #7
0
 def test_conversion_to_luv(self):
     luv = convert_color(self.color, LuvColor)
     self.assertColorMatch(luv, LuvColor(51.837, -73.561, -25.657))