当前位置: 首页>>代码示例>>Python>>正文


Python RGBColor.delta_e方法代码示例

本文整理汇总了Python中colormath.color_objects.RGBColor.delta_e方法的典型用法代码示例。如果您正苦于以下问题:Python RGBColor.delta_e方法的具体用法?Python RGBColor.delta_e怎么用?Python RGBColor.delta_e使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colormath.color_objects.RGBColor的用法示例。


在下文中一共展示了RGBColor.delta_e方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: difference

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
def difference(a, b): # HLS
	print(a, b)
	#c1 = HSLColor(hsl_h = a[0], hsl_s = a[2]/100.0, hsl_l = a[1]/100.0)
	#c2 = HSLColor(hsl_h = b[0], hsl_s = a[2]/100.0, hsl_l = a[1]/100.0)
	c1 = RGBColor(a[0], a[1], a[2])
	c2 = RGBColor(b[0], b[1], b[2])
	#c1.convert_to('lab')
	#c2.convert_to('lab')
	print(c1.delta_e(c2))
	return c1.delta_e(c2)
开发者ID:jnv,项目名称:cinemetrics,代码行数:12,代码来源:03_3_movie-colors.py

示例2: hex_me_up

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
    def hex_me_up(self):

        self.hex_value = webcolors.rgb_to_hex(self.rgb)
        snapped, colour_name = swatchbook.closest_delta_e('css3', self.hex_value)
        snapped_rgb = webcolors.hex_to_rgb(snapped)
        hsv = self.rgb_to_hsv(*snapped_rgb)
        target = RGBColor(*snapped_rgb)
        original = RGBColor(*self.rgb)
        cdist = target.delta_e(original, method="cmc")
        prom = Decimal(self.prominence).quantize(TWOPLACES)
        dist = Decimal(cdist).quantize(TWOPLACES)
        ELITE = False

        self.css = {
            'r': self.rgb[0],
            'g': self.rgb[1],
            'b': self.rgb[2],
            'hue': hsv[0],
            'hex': snapped,
            'name': colour_name,
            'distance': float(dist),
            'prominence': float(prom),
            'elite': ELITE,
        }

        return self.css
开发者ID:richbs,项目名称:colourlens,代码行数:28,代码来源:utils.py

示例3: closest_delta_e

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
    def closest_delta_e(self, hex):
        """
        Calculates the Delta E difference between a hex value and others in
        the specified palette and returns the closest match (CMC method)
        http://en.wikipedia.org/wiki/Color_difference#CMC_l:c_.281984.29
        """
        incumbent = RGBColor(*webcolors.hex_to_rgb(hex))

        shortest_dist = None
        nearest_colour = None
        for key, details in self.colours().items():

            candidate = RGBColor(*webcolors.hex_to_rgb(key))
            cdist = incumbent.delta_e(candidate, method="cmc")
            if nearest_colour is None:
                nearest_colour = (candidate, key, details)
                shortest_dist = cdist
            elif cdist < shortest_dist:
                shortest_dist = cdist
                nearest_colour = (candidate, key, details)

        details = nearest_colour[2]
        name = details['name']
        hex = self.hex(name)
        return hex, name
开发者ID:cooperhewitt,项目名称:py-cooperhewitt-swatchbook,代码行数:27,代码来源:palette.py

示例4: color_distance

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
def color_distance(color_a, color_b):
    
    from colormath.color_objects import RGBColor
    
    colora = RGBColor(rgb_r = color_a.rR, rgb_g = color_a.rG, rgb_b = color_a.rB)
    colorb = RGBColor(rgb_r = color_b.rR, rgb_g = color_b.rG, rgb_b = color_b.rB)
    
    return colora.delta_e(colorb, mode='cmc', pl=1, pc=1)
开发者ID:foxfirefey,项目名称:memewidth-styles,代码行数:10,代码来源:models.py

示例5: find_related_pixel

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [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()
开发者ID:alenoir,项目名称:instamoz_api,代码行数:60,代码来源:models.py

示例6: Color

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [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)]
开发者ID:DasIch,项目名称:utils,代码行数:57,代码来源:vim-gui-to-term.py

示例7: get_distance

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
def get_distance(pix1, pix2):
	'''Computes distance beween two colors. based on colormath if available,
	   or computes a simple euclidian distance on RGB values
	'''
	if HasColormath:
		col1 = RGBColor(pix1[0], pix1[1], pix1[2])
		col2 = RGBColor(pix2[0], pix2[1], pix2[2])
		#dist = col1.delta_e(col2, mode='cmc', pl=1, pc=1)
		dist = col1.delta_e(col2)
	else:
		dist = sqrt ( pow(pix1[0]-pix2[0],2)+pow(pix1[1]-pix2[1],2)+pow(pix1[2]-pix2[2],2) )
	return dist
开发者ID:MickaelG,项目名称:ksmosaic,代码行数:14,代码来源:color.py

示例8: closest_colour

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
def closest_colour(requested_colour):
    """Find the colour in kelly_colours that is closest to this one.
    requested_colour is an RGB tuple."""
    rlab = RGBColor(*requested_colour).convert_to("lab")
    if (30 < rlab.lab_l < 70) and abs(rlab.lab_a) + abs(rlab.lab_b) == 0:
        # This is a greyscale colour
        return "#817066"
    better_colours = {}
    for key, bits in kelly_colours.items():
        lab_diff = rlab.delta_e(bits[1])
        better_colours[lab_diff] = key
    return better_colours[min(better_colours.keys())]
开发者ID:AbsoluteDestiny,项目名称:scenic,代码行数:14,代码来源:color.py

示例9: update_shape_dominant_delta

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
def update_shape_dominant_delta(shape, save=True):
    """ Update shape dominant_delta """

    if not shape.dominant_rgb0 or not shape.dominant_rgb1:
        return

    c0 = RGBColor()
    c1 = RGBColor()
    c0.set_from_rgb_hex(shape.dominant_rgb0)
    c1.set_from_rgb_hex(shape.dominant_rgb1)
    shape.dominant_delta = c0.delta_e(c1)

    if save:
        shape.save()
开发者ID:seanbell,项目名称:opensurfaces,代码行数:16,代码来源:utils.py

示例10: compare_colors

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
    def compare_colors(self, color0, color1):
        """
        see https://de.wikipedia.org/wiki/Delta_E
        0,0 … 0,5	kein bis fast kein Unterschied
        0,5 … 1,0	Unterschied kann für das geübte Auge bemerkbar sein
        1,0 … 2,0	merklicher Farbunterschied
        2,0 … 4,0	wahrgenommener Farbunterschied
        4,0 … 5,0	wesentlicher Farbunterschied, der selten toleriert wird
        oberhalb 5,0	die Differenz wird als andere Farbe bewertet
        """
        c0 = RGBColor(color0[0], color0[1], color0[2])
        c1 = RGBColor(color1[0], color1[1], color1[2])

        return c0.delta_e(c1, mode='cie1976')
开发者ID:AlexSchwank,项目名称:CV_Game,代码行数:16,代码来源:image_operations.py

示例11: _get_color

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
    def _get_color(self):
        self.nearest = None
        self.shortest_distance = 100
        chosen_name = None

        for color_dict in (COLOURS, GREYSCALE):
            for name, color in color_dict.iteritems():
                desired_rgb = color[0]

                target = RGBColor(*desired_rgb)
                cdist = target.delta_e(RGBColor(*self.rgb), method='cmc')

                if self.nearest is None or cdist < self.shortest_distance:
                    self.nearest = name
                    self.nearest_rgb = desired_rgb

                    self.shortest_distance = cdist
                    self.distance = cdist

                # print 'Checking', name
                (hue_lo, hue_hi) = color[1]

                if hue_lo > hue_hi:
                    h = self.spin(self.hue)
                    hue_lo = self.spin(hue_lo)
                    hue_hi = self.spin(hue_hi)
                else:
                    h = self.hue

                sat_range = color[2] or DEFAULT_SAT
                val_range = color[3] or DEFAUL_VAL

                if h in range(hue_lo, hue_hi + 1) and \
                    self.sat in range(sat_range[0], sat_range[1] + 1) and \
                        self.val in range(val_range[0], val_range[1] + 1):
                    # TODO set up desirable hues, sat and b per named colour
                    target = RGBColor(*desired_rgb)
                    self.distance = cdist
                    chosen_name = name
                    self.nearest_hex = webcolors.rgb_to_hex(self.nearest_rgb)

                    return chosen_name

        return None
开发者ID:torchbox,项目名称:colourlens,代码行数:46,代码来源:utils.py

示例12: lab_distance

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
 def lab_distance(self, rgb1, rgb2):
   lab1 = RGBColor(rgb1[0],rgb1[1], rgb1[2]).convert_to('lab')
   lab2 = RGBColor(rgb2[0],rgb2[1], rgb2[2]).convert_to('lab')
   return round(lab1.delta_e(lab2), 2)
开发者ID:alex-nexus,项目名称:data_science_practice,代码行数:6,代码来源:color_indexer.py

示例13: distance

# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import delta_e [as 别名]
 def distance(self, r, g, b):
     target = RGBColor(r, g, b)
     return target.delta_e(RGBColor(*self.rgb), method="cmc")
开发者ID:donundeen,项目名称:colourpressure,代码行数:5,代码来源:colourpressure.py


注:本文中的colormath.color_objects.RGBColor.delta_e方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。