本文整理汇总了Python中colormath.color_objects.sRGBColor方法的典型用法代码示例。如果您正苦于以下问题:Python color_objects.sRGBColor方法的具体用法?Python color_objects.sRGBColor怎么用?Python color_objects.sRGBColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colormath.color_objects
的用法示例。
在下文中一共展示了color_objects.sRGBColor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_base_img
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import sRGBColor [as 别名]
def open_base_img(full_profile, res, base_color, color):
# get base image according to profile and perceptual gray of key color
base_num = str([0xE0, 0xB0, 0x80, 0x50, 0x20].index(base_color) + 1)
# open image and convert to Lab
with Image.open('images/{0}_{1}{2}.png'.format(*full_profile, base_num)) as img:
key_img = img.resize((int(s * res / 200) for s in img.size), resample=Image.BILINEAR).convert('RGBA')
if full_profile[1] in ('ISO', 'BIGENTER'): alpha = key_img.split()[-1]
l, a, b = ImageCms.applyTransform(key_img, rgb2lab_transform).split()
# convert key color to Lab
# a and b should be scaled by 128/100, but desaturation looks more natural
rgb_color = color_objects.sRGBColor(*ImageColor.getrgb(color), is_upscaled=True)
lab_color = color_conversions.convert_color(rgb_color, color_objects.LabColor)
l1, a1, b1 = lab_color.get_value_tuple()
l1, a1, b1 = int(l1 * 256 / 100), int(a1 + 128), int(b1 + 128)
# change Lab of base image to match that of key color
l = ImageMath.eval('convert(l + l1 - l_avg, "L")', l=l, l1=l1, l_avg=base_color)
a = ImageMath.eval('convert(a + a1 - a, "L")', a=a, a1=a1)
b = ImageMath.eval('convert(b + b1 - b, "L")', b=b, b1=b1)
key_img = ImageCms.applyTransform(Image.merge('LAB', (l, a, b)), lab2rgb_transform).convert('RGBA')
if full_profile[1] in ('ISO', 'BIGENTER'): key_img.putalpha(alpha)
return key_img
示例2: rgb_to_labcolor
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import sRGBColor [as 别名]
def rgb_to_labcolor(red, green, blue):
rgb_obj = sRGBColor(red, green, blue)
return convert_color(rgb_obj, LabColor)
# red = (30, 12, 6)
# blue = (6, 19, 20)
# white = (60, 100, 70)
# green = (6, 35, 13)
# yellow = (34, 43, 8)
# orange = (40, 20, 6)
示例3: test_fixtures
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import sRGBColor [as 别名]
def test_fixtures(pair):
# use colormath to confirm test values
rgb, lch = pair
cmlch = convert_color(sRGBColor(*rgb), LCHabColor).get_value_tuple()
assert _near(lch[0:2], cmlch[0:2], 0.2)
if lch[0] < 99.999999:
# If L == 100, the hue is indeterminate
# Otherwise, normalize to [0, 2*pi] and compare
h = lch[2] % (math.pi * 2)
cmh = math.radians(cmlch[2]) % (math.pi * 2)
assert _near([h], [cmh], 0.2)
示例4: rgb_to_lab
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import sRGBColor [as 别名]
def rgb_to_lab(rgb):
rgb_color = sRGBColor(rgb[0], rgb[1], rgb[2])
lab_color = convert_color(rgb_color, LabColor)
return lab_color.lab_l, lab_color.lab_a, lab_color.lab_b