本文整理汇总了Python中colormath.color_objects.RGBColor.get_rgb_hex方法的典型用法代码示例。如果您正苦于以下问题:Python RGBColor.get_rgb_hex方法的具体用法?Python RGBColor.get_rgb_hex怎么用?Python RGBColor.get_rgb_hex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colormath.color_objects.RGBColor
的用法示例。
在下文中一共展示了RGBColor.get_rgb_hex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_related_pixel
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import get_rgb_hex [as 别名]
def find_related_pixel(self):
self.is_parse = True
try:
fileimage = cStringIO.StringIO(urllib.urlopen(self.picture_url_high).read())
img = Image.open(fileimage)
imgResze = img.resize((1, 1), Image.ANTIALIAS)
pixels = list(imgResze.getdata())
except:
print 'error color pixel'
self.delete()
return True
color_insta = RGBColor(pixels[0][0],pixels[0][1],pixels[0][2])
color_hex = color_insta.get_rgb_hex()
color_hex = color_hex.replace("#", "")
self.color = color_hex
self.r_color = pixels[0][0]
self.g_color = pixels[0][1]
self.b_color = pixels[0][2]
pixel_asso = None
for subscription in self.subscriptions.all():
print 'Subscription => %s' % subscription
for mosaic in subscription.mosaics.all():
print 'Mosaic : %s' % mosaic.name
try:
img = img.resize((mosaic.pixel_size, mosaic.pixel_size), Image.ANTIALIAS)
filepath = settings.MEDIA_ROOT + '/pics/%s_%s.png' % (mosaic.pixel_size,self.id)
img.save(filepath, 'PNG')
except:
print 'error save pixel min'
return True
color_insta = RGBColor(pixels[0][0],pixels[0][1],pixels[0][2])
color_hex = color_insta.get_rgb_hex()
color_hex = color_hex.replace("#", "")
delta_e = 100
for pixel in mosaic.pixels.filter(pic__isnull=True):
pixel_color = RGBColor(pixel.r_color,pixel.g_color,pixel.b_color)
delta_e_new = color_insta.delta_e(pixel_color)
#print '#'+pixel.color
#print color_insta.get_rgb_hex()
#print delta_e_new
if delta_e_new < delta_e:
delta_e = delta_e_new
pixel_asso = pixel
print 'minimum delta_e %s' % delta_e
if pixel_asso:
if delta_e < 25:
print 'set pixel %s with delta %s' % (pixel_asso.id,delta_e)
pixel_asso.pic = self
pixel_asso.save()
self.add_to_fake_mosaic(mosaic, pixel_asso)
self.save()
示例2: Color
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import get_rgb_hex [as 别名]
class Color(object):
@classmethod
def from_string(cls, string):
if not string.startswith('#'):
raise ValueError(string)
if len(string) == 4:
args = [int(x * 2, 16) for x in string[1:]]
elif len(string) == 7:
args = [int(string[i:i + 2], 16) for i in xrange(1, 7, 2)]
else:
raise ValueError(string)
return cls(*args)
@classmethod
def from_index(cls, index):
return cls(*INDEX_TO_COLOR[index])
def __init__(self, red, green, blue):
self.color = RGBColor(red, green, blue)
@property
def red(self):
return self.color.rgb_r
@property
def green(self):
return self.color.rgb_g
@property
def blue(self):
return self.color.rgb_b
def __eq__(self, other):
return self.to_int() == other.to_int()
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return self.to_int()
def to_string(self):
return self.color.get_rgb_hex()
def to_int(self):
return COLOR_TO_INDEX[self.red, self.green, self.blue]
def difference_to(self, color):
return self.color.delta_e(color.color)
def closest(self, colors):
rv = {}
for color in colors:
rv[color.difference_to(self)] = color
return rv[min(rv)]
示例3: set_rgb
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import get_rgb_hex [as 别名]
def set_rgb(self, rgb):
'''
Pass an RGB value to the classifier
'''
rgb = RGBColor(*rgb)
logger.debug(rgb.get_rgb_hex())
self.lab = rgb.convert_to('lab')
logger.debug('Saved lab: {lab} from rgb: {rgb}'.format(
lab=self._lab_to_tuple(self.lab),
rgb=rgb))
self._update_lab_colors()
示例4: refresh_values
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import get_rgb_hex [as 别名]
def refresh_values(self):
if not self.color_hex.islower():
self.color_hex = self.color_hex.lower()
# get rgb and hsv values
rgbcolor = RGBColor()
rgbcolor.set_from_rgb_hex(self.color_hex)
hsvcolor = rgbcolor.convert_to('hsv')
self.R = rgbcolor.rgb_r
self.G = rgbcolor.rgb_g
self.B = rgbcolor.rgb_b
self.H = round(hsvcolor.hsv_h)
# need to multiply by 100 to get the percent
self.S = round(hsvcolor.hsv_s * 100.0)
self.V = round(hsvcolor.hsv_v * 100.0)
# make rounded values
self.rR = round_rgb_colorvalue(self.R)
self.rG = round_rgb_colorvalue(self.G)
self.rB = round_rgb_colorvalue(self.B)
round_rgb = RGBColor(rgb_r = self.rR, rgb_g = self.rG, rgb_b = self.rB)
round_hsv = round_rgb.convert_to('hsv')
self.rounded_hex = round_rgb.get_rgb_hex()[1:7]
self.rH = round_hsv.hsv_h
self.rS = round_hsv.hsv_s
self.rV = round_hsv.hsv_v
# check to see if this is a round color
if self.R == self.rR and self.G == self.rG and self.B == self.rB:
self.is_round = True
else:
self.is_round = False
示例5: RGBConversionTestCase
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import get_rgb_hex [as 别名]
class RGBConversionTestCase(BaseColorConversionTest):
def setUp(self):
self.color = RGBColor(0.482, 0.784, 0.196, rgb_type='sRGB')
def test_to_xyz_and_back(self):
xyz = convert_color(self.color, XYZColor)
rgb = convert_color(xyz, RGBColor)
self.assertColorMatch(rgb, self.color)
def test_conversion_to_hsl_max_r(self):
color = RGBColor(255, 123, 50, rgb_type='sRGB', is_upscaled=True)
hsl = convert_color(color, HSLColor)
self.assertColorMatch(hsl, HSLColor(21.366, 1.000, 0.598))
def test_conversion_to_hsl_max_g(self):
color = RGBColor(123, 255, 50, rgb_type='sRGB', is_upscaled=True)
hsl = convert_color(color, HSLColor)
self.assertColorMatch(hsl, HSLColor(98.634, 1.000, 0.598))
def test_conversion_to_hsl_max_b(self):
color = RGBColor(0.482, 0.482, 1.0, rgb_type='sRGB')
hsl = convert_color(color, HSLColor)
self.assertColorMatch(hsl, HSLColor(240.000, 1.000, 0.741))
def test_conversion_to_hsl_gray(self):
color = RGBColor(0.482, 0.482, 0.482, rgb_type='sRGB')
hsl = convert_color(color, HSLColor)
self.assertColorMatch(hsl, HSLColor(0.000, 0.000, 0.482))
def test_conversion_to_hsv(self):
hsv = convert_color(self.color, HSVColor)
self.assertColorMatch(hsv, HSVColor(90.816, 0.750, 0.784))
def test_conversion_to_cmy(self):
cmy = convert_color(self.color, CMYColor)
self.assertColorMatch(cmy, CMYColor(0.518, 0.216, 0.804))
def test_srgb_conversion_to_xyz_d50(self):
"""
sRGB's native illuminant is D65. Test the XYZ adaptations by setting
a target illuminant to something other than D65.
"""
xyz = convert_color(self.color, XYZColor, target_illuminant='D50')
self.assertColorMatch(xyz, XYZColor(0.313, 0.460, 0.082))
def test_srgb_conversion_to_xyz_d65(self):
"""
sRGB's native illuminant is D65. This is a straightforward conversion.
"""
xyz = convert_color(self.color, XYZColor)
self.assertColorMatch(xyz, XYZColor(0.294, 0.457, 0.103))
def test_adobe_conversion_to_xyz_d65(self):
"""
Adobe RGB's native illuminant is D65, like sRGB's. However, sRGB uses
different conversion math that uses gamma, so test the alternate logic
route for non-sRGB RGB colors.
"""
adobe = RGBColor(0.482, 0.784, 0.196, rgb_type='adobe_rgb')
xyz = convert_color(adobe, XYZColor)
self.assertColorMatch(xyz, XYZColor(0.230, 0.429, 0.074))
def test_adobe_conversion_to_xyz_d50(self):
"""
Adobe RGB's native illuminant is D65, so an adaptation matrix is
involved here. However, the math for sRGB and all other RGB types is
different, so test all of the other types with an adaptation matrix
here.
"""
adobe = RGBColor(0.482, 0.784, 0.196, rgb_type='adobe_rgb')
xyz = convert_color(adobe, XYZColor, target_illuminant='D50')
self.assertColorMatch(xyz, XYZColor(0.247, 0.431, 0.060))
def test_convert_to_self(self):
same_color = convert_color(self.color, RGBColor)
self.assertEqual(self.color, same_color)
def test_get_rgb_hex(self):
hex_str = self.color.get_rgb_hex()
self.assertEqual(hex_str, "#7bc832", "sRGB to hex conversion failed")
def test_set_from_rgb_hex(self):
rgb = RGBColor.new_from_rgb_hex('#7bc832')
self.assertColorMatch(rgb, RGBColor(0.482, 0.784, 0.196))