本文整理匯總了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