本文整理汇总了Python中colormath.color_objects.LabColor方法的典型用法代码示例。如果您正苦于以下问题:Python color_objects.LabColor方法的具体用法?Python color_objects.LabColor怎么用?Python color_objects.LabColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colormath.color_objects
的用法示例。
在下文中一共展示了color_objects.LabColor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_base_img
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import LabColor [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: handle
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import LabColor [as 别名]
def handle(self, *args, **options):
height = 16
bar = np.zeros((256, height, 3))
for i in xrange(256):
t = i / 255.0
lab0 = np.array([40, 30, -70])
lab1 = np.array([70, 30, 70])
lab = t * lab0 + (1 - t) * lab1
rgb = np.clip(LabColor(*lab).convert_to('rgb').get_value_tuple(), 0, 255)
for j in xrange(height):
bar[i, j, :] = rgb / 255.0
image = numpy_to_pil(bar)
image.save('bar.png')
print "Saved to bar.png"
示例3: svg_style
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import LabColor [as 别名]
def svg_style(self):
""" Return the svg style attribute """
if self.darker:
if self.darker_method == 'A':
return 'fill: #49D36A'
else:
t = np.clip(abs(self.darker_score), 0, 1)
lab0 = np.array([40, 30, -70])
lab1 = np.array([70, 30, 70])
lab = t * lab0 + (1 - t) * lab1
rgb = np.clip(LabColor(*lab).convert_to('rgb').get_value_tuple(), 0, 255)
return 'fill: #%02x%02x%02x' % tuple(rgb.astype(int))
else:
return ""
示例4: rgb_to_labcolor
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import LabColor [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)
示例5: rgb_to_lab
# 需要导入模块: from colormath import color_objects [as 别名]
# 或者: from colormath.color_objects import LabColor [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