예제 #1
0
def select_task_by_priority(conn, L, A, B):
    result = []
    root = tk.Tk()

    cur = conn.cursor()
    cur.execute("SELECT Partnumber,Colorname,L,A,B FROM reading ")
    rows = cur.fetchall()
    color1 = LabColor(lab_l=L, lab_a=A, lab_b=B)
    for row in rows:
        color2 = LabColor(lab_l=row[2], lab_a=row[3], lab_b=row[4])
        if (delta_e_cie1976(color1, color2) < 100):
            result.append(row[0:2])
            result.extend(delta_e_cie1976(color1, color2))

    print(result)
예제 #2
0
def labDiff(self, color1, color2):
    # Find the difference for two lab CIE colors: https://python-colormath.readthedocs.io/en/latest/delta_e.html
    lab1 = LabColor(color1[0], color1[1], color1[2])
    lab2 = LabColor(color2[0], color2[1], color2[2])

    delta_e = delta_e_cie1976(lab1, lab2)
    return delta_e
예제 #3
0
def colorCloseEnough(color1, color2):
    rgb1 = sRGBColor(color1[0], color1[1], color1[2])
    rgb2 = sRGBColor(color2[0], color2[1], color2[2])
    lab1 = convert_color(rgb1, LabColor)
    lab2 = convert_color(rgb2, LabColor)

    return delta_e_cie1976(lab1, lab2) < 5000
예제 #4
0
def deltaE(mongoCollection, r1, g1, b1):

    # loading mongoDB to pandas dataFrame
    df = pd.DataFrame(list(mongoCollection.find()))

    # initializing return index with base values
    idx = [0, math.inf]
    rgb1 = sRGBColor(r1, g1, b1, is_upscaled=True)
    lab1 = convert_color(rgb1, LabColor)
    # calculating lowest deltaE value
    for index, row in df.iterrows():
        r2 = row['R']
        g2 = row['G']
        b2 = row['B']
        rgb2 = sRGBColor(r2, g2, b2, is_upscaled=True)
        lab2 = convert_color(rgb2, LabColor)

        delta_e = delta_e_cie1976(lab1, lab2)

        if delta_e < idx[1]:
            idx = [index, delta_e]
        else:
            continue

        rgb = [
            df.iloc[idx[0]]['R'], df.iloc[idx[0]]['G'], df.iloc[idx[0]]['B']
        ]

    #returns rgb value with lowest deltaE in dataset
    return rgb
예제 #5
0
def colorCloseEnough(color1, color2):
    rgb1 = sRGBColor(color1[0], color1[1], color1[2])
    rgb2 = sRGBColor(color2[0], color2[1], color2[2])
    lab1 = convert_color(rgb1, LabColor)
    lab2 = convert_color(rgb2, LabColor)

    return delta_e_cie1976(lab1, lab2) < 5000
예제 #6
0
 def test_cie1976_accuracy(self):
     result = delta_e_cie1976(self.color1, self.color2)
     expected = 2.151
     self.assertAlmostEqual(
         result, expected, 3,
         "DeltaE CIE1976 formula error. Got %.3f, expected %.3f (diff: %.3f)."
         % (result, expected, result - expected))
예제 #7
0
    def delta_e(self, other_color, mode='cie2000', *args, **kwargs):
        """
        Compares this color to another via Delta E.

        Valid modes:
         cie2000
         cie1976
        """
        if not isinstance(other_color, ColorBase):
            raise InvalidArgument('delta_e_cie2000', 'other_color', other_color)

        # Convert the colors to Lab if they are not already.
        lab1 = self.convert_to('lab', *args, **kwargs)
        lab2 = other_color.convert_to('lab', *args, **kwargs)

        mode = mode.lower()
        if mode == 'cie2000':
            return color_diff.delta_e_cie2000(lab1, lab2)
        elif mode == 'cie1994':
            return color_diff.delta_e_cie1994(lab1, lab2, **kwargs)
        elif mode == 'cie1976':
            return color_diff.delta_e_cie1976(lab1, lab2)
        elif mode == 'cmc':
            return color_diff.delta_e_cmc(lab1, lab2, **kwargs)
        else:
            raise InvalidDeltaEMode(mode)
예제 #8
0
 def distance_lab(c1, c2):
     "Color distance in the Lab colorimetric space."
     color1 = sRGBColor(*c1[:3], is_upscaled=True)
     color1_lab = convert_color(color1, LabColor)
     color2 = sRGBColor(*c2[:3], is_upscaled=True)
     color2_lab = convert_color(color2, LabColor)
     return delta_e_cie1976(color1_lab, color2_lab)
예제 #9
0
 def delta_e(self, other_color, mode='cie2000', *args, **kwargs):
     """
     Compares this color to another via Delta E.
     
     Valid modes:
      cie2000
      cie1976
     """
     if not isinstance(other_color, ColorBase):
         raise InvalidArgument('delta_e_cie2000', 'other_color', other_color)
     
     # Convert the colors to Lab if they are not already.
     lab1 = self.convert_to('lab', *args, **kwargs)
     lab2 = other_color.convert_to('lab', *args, **kwargs)
     
     mode = mode.lower()
     if mode == 'cie2000':
         return delta_e_cie2000(lab1, lab2)
     elif mode == 'cie1994':
         return delta_e_cie1994(lab1, lab2, **kwargs)
     elif mode == 'cie1976':
         return delta_e_cie1976(lab1, lab2)
     elif mode == 'cmc':
         return delta_e_cmc(lab1, lab2, **kwargs)
     else:
         raise InvalidDeltaEMode(mode)
예제 #10
0
파일: ansify.py 프로젝트: coljac/ansify
def color_difference(color1, color2):
    c1 = convert_color(sRGBColor(*color1), LabColor, target_illuminant='d50')
    c2 = convert_color(sRGBColor(*color2), LabColor, target_illuminant='d50')
    # c1 = LabColor(lab_l=0.9, lab_a=16.3, lab_b=-2.22)
    # c2 = LabColor(lab_l=0.7, lab_a=14.2, lab_b=-1.80)
    delta_e = delta_e_cie1976(c1, c2)
    return delta_e
예제 #11
0
def comparePixels(arr1, arr2, eps=0.001):
    rgb_pixel1 = [[arr1]]
    rgb_pixel2 = [[arr2]]
    lab1 = color.rgb2lab(rgb_pixel1)
    lab2 = color.rgb2lab(rgb_pixel2)
    color1 = LabColor(lab1[0][0][0], lab1[0][0][1], lab1[0][0][2])
    color2 = LabColor(lab2[0][0][0], lab2[0][0][1], lab2[0][0][2])
    if delta_e_cie1976(color1, color2) <= eps:
        return True
    return False
def DeltaCalculator(CIE, LabCH, delta):
    lab_reference = LabColor(lab_l=CIE[0], lab_a=CIE[1], lab_b=CIE[2])
    lab = LabColor(lab_l=LabCH[0], lab_a=LabCH[1], lab_b=LabCH[2])
    if delta == 'delta_e_cie1976':
        return delta_e_cie1976(lab, lab_reference)
    elif delta == 'delta_e_cie1994':
        return delta_e_cie1994(lab, lab_reference)
    elif delta == 'delta_e_cie2000':
        return delta_e_cie2000(lab, lab_reference)
    else:
        return delta_e_cmc(lab, lab_reference)
예제 #13
0
 def color_distance_lab2(rgb_1, rgb_2):
     from colormath.color_objects import LabColor
     from colormath.color_diff import delta_e_cie1976
     lab1 = RGB2Lab(rgb_1[::-1])
     lab2 = RGB2Lab(rgb_2[::-1])
     # Reference color.
     color1 = LabColor(lab_l=lab1[0], lab_a=lab1[1], lab_b=lab1[2])
     # Color to be compared to the reference.
     color2 = LabColor(lab_l=lab2[0], lab_a=lab2[1], lab_b=lab2[2])
     # This is your delta E value as a float.
     delta_e = delta_e_cie1976(color1, color2)
     return delta_e
예제 #14
0
def colordiff_lab(pixel1, pixel2):

    #convert rgb values to L*ab values
    rgb_pixel_1 = sRGBColor(pixel1[0], pixel1[1], pixel1[2], True)
    lab_1 = convert_color(rgb_pixel_1, LabColor)

    rgb_pixel_2 = sRGBColor(pixel2[0], pixel2[1], pixel2[2], True)
    lab_2 = convert_color(rgb_pixel_2, LabColor)

    #calculate delta e
    delta_e = delta_e_cie1976(lab_1, lab_2)
    return delta_e
예제 #15
0
def colordiff_lab(pixel1,pixel2):

	#convert rgb values to L*ab values
	rgb_pixel_1=sRGBColor(pixel1[0],pixel1[1],pixel1[2],True)
	lab_1= convert_color(rgb_pixel_1, LabColor)

	rgb_pixel_2=sRGBColor(pixel2[0],pixel2[1],pixel2[2],True)
	lab_2= convert_color(rgb_pixel_2, LabColor)

	#calculate delta e
	delta_e = delta_e_cie1976(lab_1, lab_2)
	return delta_e
예제 #16
0
def colordiff_lab(source_pixel,palette_pixel):

	#convert rgb values to L*ab values
	rgb_pixel_source=sRGBColor(source_pixel[0],source_pixel[1],source_pixel[2],True)
	lab_source= convert_color(rgb_pixel_source, LabColor)

	rgb_pixel_palette=sRGBColor(palette_pixels[0],palette_pixels[1],palette_pixels[2],True)
	lab_palette= convert_color(rgb_pixel_palette, LabColor)

	#calculate delta e
	delta_e = delta_e_cie1976(lab_source, lab_palette)
	return delta_e
예제 #17
0
def colordiff_lab(pixel1,pixel2):

	#convert rgb values to L*ab values
	rgb_pixel_source=sRGBColor(pixel1[0],pixel1[1],pixel1[2],True)
	lab_source= convert_color(rgb_pixel_source, LabColor)

	rgb_pixel_palette=sRGBColor(pixel2[0],pixel2[1],pixel2[2],True)
	lab_palette= convert_color(rgb_pixel_palette, LabColor)

	#calculate delta e
	delta_e = delta_e_cie1976(lab_source, lab_palette)
	return delta_e
예제 #18
0
def colordiff_lab(pixel1, pixel2):

    #convert rgb values to L*ab values
    rgb_pixel_source = sRGBColor(pixel1[0], pixel1[1], pixel1[2], True)
    lab_source = convert_color(rgb_pixel_source, LabColor)

    rgb_pixel_palette = sRGBColor(pixel2[0], pixel2[1], pixel2[2], True)
    lab_palette = convert_color(rgb_pixel_palette, LabColor)

    #calculate delta e
    delta_e = delta_e_cie1976(lab_source, lab_palette)
    return delta_e
예제 #19
0
def Delta_E(LabPic):
    color = (0,0,0)
    min_delta_e = 99999
    for rgbColor in tester_colors:
        sRGB = sRGBColor(rgbColor[0]/255,rgbColor[1]/255,rgbColor[2]/255)  #s = small rgb by divided 255
        xyz = convert_color(sRGB, XYZColor, target_illuminant='d65')
        LabTester = convert_color(xyz, LabColor)
        delta_e = delta_e_cie1976(LabPic, LabTester)
        #print("delta_e of color",rgbColor,"is", delta_e)
        if delta_e < min_delta_e:
            min_delta_e = delta_e
            color = rgbColor
    return color
예제 #20
0
def colordiff_lab(source_pixel, palette_pixel):

    #convert rgb values to L*ab values
    rgb_pixel_source = sRGBColor(source_pixel[0], source_pixel[1],
                                 source_pixel[2], True)
    lab_source = convert_color(rgb_pixel_source, LabColor)

    rgb_pixel_palette = sRGBColor(palette_pixels[0], palette_pixels[1],
                                  palette_pixels[2], True)
    lab_palette = convert_color(rgb_pixel_palette, LabColor)

    #calculate delta e
    delta_e = delta_e_cie1976(lab_source, lab_palette)
    return delta_e
def get_color_distance(c1, c2, on_server):
    if (c1, c2) in dcache:
        return dcache[(c1, c2)]

    if (c2, c1) in dcache:
        return dcache[(c2, c1)]

    # delta_e_cie2000 is better but is 3x slower on an EV3...1976 is good enough
    if on_server:
        distance = delta_e_cie2000(c1, c2)
    else:
        distance = delta_e_cie1976(c1, c2)

    dcache[(c1, c2)] = distance
    return distance
예제 #22
0
def matchPicToPixelByColor(pxlList, picList):
    "matches the pixel-colors of the meta image to the average color of the small pictures"
    pxlListLab = turnToLabColors(pxlList)
    picListLab = turnToLabColors(picList)
    matches = []
    for i in range(len(pxlListLab)):
        clsMI = 1000000000.0
        closestMatch = None
        for j in range(len(picListLab)):
            delta_e = delta_e_cie1976(pxlListLab[i], picListLab[j][0])
            if (delta_e < clsMI):
                closestMatch = picListLab[j][1]
                clsMI = delta_e
        matches.append((pxlList[i], closestMatch))
    return matches
예제 #23
0
def get_color_distance(c1, c2, on_server):
    if (c1, c2) in dcache:
        return dcache[(c1, c2)]

    if (c2, c1) in dcache:
        return dcache[(c2, c1)]

    # delta_e_cie2000 is better but is 3x slower on an EV3...1976 is good enough
    if on_server:
        distance = delta_e_cie2000(c1, c2)
    else:
        distance = delta_e_cie1976(c1, c2)

    dcache[(c1, c2)] = distance
    return distance
예제 #24
0
def son_colores_parecidos(color1, color2):
    '''Usa la librería colormath para determinar si un par de colores es parecido y devuelve verdadero en ese caso'''
    from colormath.color_objects import AdobeRGBColor, LabColor, XYZColor
    from colormath.color_conversions import convert_color
    from colormath.color_diff import delta_e_cie1976

    try:
        color1 = AdobeRGBColor.new_from_rgb_hex(color1)
        color2 = AdobeRGBColor.new_from_rgb_hex(color2)
        delta_e = delta_e_cie1976(convert_color(color1, LabColor),
                                  convert_color(color2, LabColor))
        print('delta color: ', delta_e)
        #print(abs(delta_e)<50)
        return abs(delta_e) < 50

    except ValueError:
        print('Elige un color')
        return False
예제 #25
0
    def refresh(self):
        full_data = self.request('GET',
                                 "http://www.cal-print.com/InkColorChart.htm")
        tds = full_data.find_all('td', attrs={"bgcolor": re.compile(r".*")})

        raw_data = {}
        known_names = []
        for td in tds:
            table = td.find_parent('table')
            name = table.find("font").text
            color = self.hex_to_rgb(td['bgcolor'])

            # remove excess whitespace
            name = re.sub(re.compile(r"\s+"), " ", name.strip())
            if 'PMS' not in name and 'Pantone' not in name:
                name = 'Pantone ' + name
            raw_data[name] = color

            if not name.startswith('PMS'):
                known_names.append(name)
        # Add white
        raw_data['White'] = [255, 255, 255]
        known_names.append('White')

        # Find distance between colors and find better names for unnamed
        # colors in the table.
        data = {}
        for name, color in raw_data.items():
            rgb = sRGBColor(*color)
            lab = convert_color(rgb, LabColor, target_illuminant='D65')
            min_diff = float("inf")
            min_name = ""
            for known_name in known_names:
                known_color = raw_data[known_name]
                known_rgb = sRGBColor(*known_color)
                known_lab = convert_color(known_rgb, LabColor,
                                          target_illuminant='D65')
                diff = delta_e_cie1976(lab, known_lab)
                if min_diff > diff:
                    min_diff = diff
                    min_name = known_name
            data['{0} ({1})'.format(name, min_name)] = color
        return data
예제 #26
0
def fitness_lab(source_im,palette_im):
	source_pixels=list(source_im.getdata())
	palette_pixels=list(palette_im.getdata())

	fit=0.0
	for i in xrange(len(palette_pixels)):
		#convert rgb values to L*ab values
		rgb_pixel_source=sRGBColor(source_pixels[i][0],source_pixels[i][1],source_pixels[i][2],True)
		lab_source= convert_color(rgb_pixel_source, LabColor)

		rgb_pixel_palette=sRGBColor(palette_pixels[i][0],palette_pixels[i][1],palette_pixels[i][2],True)
		lab_palette= convert_color(rgb_pixel_palette, LabColor)

		#calculate delta e
		delta_e = delta_e_cie1976(lab_source, lab_palette)

		fit+=delta_e

	return fit
def findNearestColor(thiscolor,x,y):
 minDist=10000
 global colordict
 mincolor=[0,0,0]
 for item in colordict.keys():
  testcolorlist=[float(i) for i in item.split(',')]
  cl1=LabColor(testcolorlist[0],testcolorlist[1],testcolorlist[2])
  cl2=LabColor(thiscolor[0],thiscolor[1],thiscolor[2])
  dist=delta_e_cie1976(cl1,cl2)
  if dist<minDist:
   minDist=dist
   mincolor=np.array(testcolorlist)

 if minDist<colorthreshold:
  colordict[item].append((x,y)) 
  return mincolor
 else:
  keylist=[str(i) for i in list(thiscolor)]
  colordict[','.join(keylist)]=[(x,y)]
  return None
예제 #28
0
def findNearestColor(thiscolor, x, y):
    minDist = 10000
    global colordict
    mincolor = [0, 0, 0]
    for item in colordict.keys():
        testcolorlist = [float(i) for i in item.split(',')]
        cl1 = LabColor(testcolorlist[0], testcolorlist[1], testcolorlist[2])
        cl2 = LabColor(thiscolor[0], thiscolor[1], thiscolor[2])
        dist = delta_e_cie1976(cl1, cl2)
        if dist < minDist:
            minDist = dist
            mincolor = np.array(testcolorlist)

    if minDist < colorthreshold:
        colordict[item].append((x, y))
        return mincolor
    else:
        keylist = [str(i) for i in list(thiscolor)]
        colordict[','.join(keylist)] = [(x, y)]
        return None
예제 #29
0
    def find_closest(self, color):
        """
        Find the closest color in the system to the given rgb values.

        :param color: Tuple of r, g, b values (scaled to 255).
        :returns:     Tuple of name and rgb closest to the given color.
        """
        # Find distance between colors and find name based on closest color
        rgb = sRGBColor(*color)
        lab = convert_color(rgb, LabColor, target_illuminant='D65')
        min_diff = float("inf")
        min_name, min_color = "", ()
        for known_name, known_color in self.items():
            known_rgb = sRGBColor(*known_color)
            known_lab = convert_color(known_rgb, LabColor,
                                      target_illuminant='D65')
            diff = delta_e_cie1976(lab, known_lab)
            if min_diff > diff:
                min_diff = diff
                min_name = known_name
                min_color = known_color
        return min_name, min_color
예제 #30
0
def fitness_lab(source_im, palette_im):
    source_pixels = list(source_im.getdata())
    palette_pixels = list(palette_im.getdata())

    fit = 0.0
    for i in xrange(len(palette_pixels)):
        #convert rgb values to L*ab values
        rgb_pixel_source = sRGBColor(source_pixels[i][0], source_pixels[i][1],
                                     source_pixels[i][2], True)
        lab_source = convert_color(rgb_pixel_source, LabColor)

        rgb_pixel_palette = sRGBColor(palette_pixels[i][0],
                                      palette_pixels[i][1],
                                      palette_pixels[i][2], True)
        lab_palette = convert_color(rgb_pixel_palette, LabColor)

        #calculate delta e
        delta_e = delta_e_cie1976(lab_source, lab_palette)

        fit += delta_e

    return fit
예제 #31
0
    def find_closest(self, color):
        """
        Find the closest color in the system to the given rgb values.

        :param color: Tuple of r, g, b values (scaled to 255).
        :returns:     Tuple of name and rgb closest to the given color.
        """
        # Find distance between colors and find name based on closest color
        rgb = sRGBColor(*color)
        lab = convert_color(rgb, LabColor, target_illuminant='D65')
        min_diff = float("inf")
        min_name, min_color = "", ()
        for known_name, known_color in self.items():
            known_rgb = sRGBColor(*known_color)
            known_lab = convert_color(known_rgb,
                                      LabColor,
                                      target_illuminant='D65')
            diff = delta_e_cie1976(lab, known_lab)
            if min_diff > diff:
                min_diff = diff
                min_name = known_name
                min_color = known_color
        return min_name, min_color
예제 #32
0
파일: core.py 프로젝트: alexpnt/pixel-art
    def colordiff_lab(pixel1: Tuple, pixel2: Tuple) -> float:
        """Computes the color difference between two pixels, in the Lab* color space.

        A small value will lead to better results.
        Working in the Lab* color space provides better accuracies, but it is a slower method.

        Args:
          pixel1: A tuple containing one pixel value.
          pixel2: A tuple containing another pixel value.

        Returns:
            A float value representing the color difference between the two pixels.
        """
        # convert rgb values to L*ab values
        rgb_pixel_source = sRGBColor(pixel1[0], pixel1[1], pixel1[2], True)
        lab_source = convert_color(rgb_pixel_source, LabColor)

        rgb_pixel_palette = sRGBColor(pixel2[0], pixel2[1], pixel2[2], True)
        lab_palette = convert_color(rgb_pixel_palette, LabColor)

        # calculate delta e
        delta_e = delta_e_cie1976(lab_source, lab_palette)
        return delta_e
예제 #33
0
def distance(spectrum_pnt, pnt, mode):
    color1 = LabColor(lab_l=spectrum_pnt[0],
                      lab_a=spectrum_pnt[1],
                      lab_b=spectrum_pnt[2])
    color2 = LabColor(lab_l=pnt[0], lab_a=pnt[1], lab_b=pnt[2])
    if mode == 'cie1976':
        return color_diff.delta_e_cie1976(color1, color2)
    elif mode == 'cie1994':
        return color_diff.delta_e_cie1994(color1,
                                          color2,
                                          K_L=1,
                                          K_C=1,
                                          K_H=1,
                                          K_1=0.045,
                                          K_2=0.015)
    elif mode == 'cie2000':
        return color_diff.delta_e_cie2000(color1, color2, Kl=1, Kc=1, Kh=1)
    elif mode == 'cmc':
        return color_diff.delta_e_cmc(color1, color2, pl=2, pc=1)
    else:
        return np.sqrt((spectrum_pnt[0] - pnt[0])**2 +
                       (spectrum_pnt[1] - pnt[1])**2 +
                       (spectrum_pnt[2] - pnt[2])**2)
예제 #34
0
def colorz(filename, n=5):
    img = Image.open(filename)
    img.thumbnail((200, 200))
    w, h = img.size
    
    points = get_points(img)
    clusters = kmeans(points, n, 1)
    rgbs = [map(int, c.center.coords) for c in clusters]
    col_dict={} # using dictionary to store the colors as keys
    # I will also store the lab difference into it
    # then output as a csv file
    col_dict['index']=['html_color','r,g,b','black','gray','sliver','white','maroon','red','olive','yellow','green','lime','teal','aqua','navy','blue','orange','purple','fuchsia','brown']
    counter=1
    for col in rgbs:
        col_index=filename+str(counter)
        html=rtoh(col)
        scale_rgbs= sRGBColor(col[0]/255.0,col[1]/255.0,col[2]/255.0)
        lab_n = convert_color(scale_rgbs, LabColor)
        
        #compared with other basic colors:
        de_black= delta_e_cie1976(lab_n, black)
        de_gray= delta_e_cie1976(lab_n, gray)
        de_sliver= delta_e_cie1976(lab_n, sliver)
        de_orange= delta_e_cie1976(lab_n, orange)
        de_purple= delta_e_cie1976(lab_n, purple)
        de_fuchsia= delta_e_cie1976(lab_n, fuchsia)
        de_brown= delta_e_cie1976(lab_n, brown)

        # store the html color as the first col
        col_dict[col_index]=[html,tuple(col),de_black,de_gray,de_sliver,de_white,de_maroon,de_red,de_olive,de_yellow,de_green,de_lime,de_teal,de_aqua,de_navy,de_blue,de_orange,de_purple,de_fuchsia,de_brown]
        counter+=1

    # I can only store the difference 
    # col_dict[col]=tuple(lab_n)
    #col_dict[col]=lab_n
    # input another function to comapre between colors and basic colors
    #delta_e = delta_e_cie1976(color1, color2)
    return col_dict
예제 #35
0
This module shows some examples of Delta E calculations of varying types.
"""

# Does some sys.path manipulation so we can run examples in-place.
# noinspection PyUnresolvedReferences
import example_config

from colormath.color_objects import LabColor
from colormath.color_diff import delta_e_cie1976, delta_e_cie1994, \
    delta_e_cie2000, delta_e_cmc

# Reference color.
color1 = LabColor(lab_l=0.9, lab_a=16.3, lab_b=-2.22)
# Color to be compared to the reference.
color2 = LabColor(lab_l=0.7, lab_a=14.2, lab_b=-1.80)

print("== Delta E Colors ==")
print(" COLOR1: %s" % color1)
print(" COLOR2: %s" % color2)
print("== Results ==")
print(" CIE1976: %.3f" % delta_e_cie1976(color1, color2))
print(" CIE1994: %.3f (Graphic Arts)" % delta_e_cie1994(color1, color2))
# Different values for textiles.
print(" CIE1994: %.3f (Textiles)" % delta_e_cie1994(color1,
    color2, K_1=0.048, K_2=0.014, K_L=2))
print(" CIE2000: %.3f" % delta_e_cie2000(color1, color2))
# Typically used for acceptability.
print("     CMC: %.3f (2:1)" % delta_e_cmc(color1, color2, pl=2, pc=1))
# Typically used to more closely model human perception.
print("     CMC: %.3f (1:1)" % delta_e_cmc(color1, color2, pl=1, pc=1))
def distance(c1, c2):
  return delta_e_cie1976(LabColor(*c1), LabColor(*c2))
예제 #37
0
def isPixelTarget(pixel):
    if pixel[1] > 10:
        return False
    pixelValue = pixel2lab(pixel)
    colorDiff = delta_e_cie1976(targetValue, pixelValue)
    return colorDiff < colorDiffThreshold
예제 #38
0
파일: colour.py 프로젝트: jamietanna/wp-py
def rgb_compare_delta_e(rgb_1, rgb_2):
    """
    Compare two rgb colours, and return the DeltaE value as per 
     the colormath library
    """
    return delta_e_cie1976(rgb_to_lab_color(rgb_1), rgb_to_lab_color(rgb_2))
예제 #39
0
if True:
	from colormath.color_objects import LabColor
	from colormath.color_diff import delta_e_cie1976

	import Bridson_Common
	filename = 'alexas_fotos--mFVHEzRvsQ-unsplash_weave.jpg'
	blurredArray = Bridson_Common.getLabBlurredImage(filename, 7)

	print(blurredArray)
	color1 = blurredArray[100,100]
	color2 = blurredArray[50,50]
	lab1 = LabColor(color1[0], color1[1], color1[2])
	lab2 = LabColor(color2[0], color2[1], color2[2])

	delta_e = delta_e_cie1976(lab1, lab2)
	print("Delta e lab1, lab2:", delta_e)

	delta_e = delta_e_cie1976(lab2, lab1)
	print("Delta e lab2, lab1:", delta_e)
# plt.imshow(blurredArray)
	# plt.show()



	# # Reference color.
	# color1 = LabColor(lab_l=0.9, lab_a=16.3, lab_b=-2.22)
	# # Color to be compared to the reference.
	# color2 = LabColor(lab_l=0.7, lab_a=14.2, lab_b=-1.80)
	# # This is your delta E value as a float.
	# delta_e = delta_e_cie1976(color1, color2)
예제 #40
0
 def distance(self, lab_cf):
     self.delta_e = delta_e_cie1976(self.lab, lab_cf)
예제 #41
0
파일: temp.py 프로젝트: tgkei/design_sprint
def output(color_type, dir):
    rgb_img = imageio.imread(dir)

    Red = []
    Green = []
    Blue = []
    for x in rgb_img:
        for y in x:
            Red.append(y[0])
            Green.append(y[1])
            Blue.append(y[2])

    R_avg = sum(Red) / len(Red)
    G_avg = sum(Green) / len(Green)
    B_avg = sum(Blue) / len(Blue)

    if R_avg < 0 or R_avg > 255 or G_avg < 0 or G_avg > 255 or B_avg < 0 or B_avg > 255:
        print("Wrong RGB")
        exit(0)

    rgb = sRGBColor(R_avg, G_avg, B_avg, is_upscaled=True)
    lab = convert_color(rgb, LabColor, through_rgb_type=sRGBColor)

    #minimum = inf
    ret = ""

    if color_type == "eye":
        for color, rgb in eyes.items():
            #            flag = minimum
            tmp_r, tmp_g, tmp_b = rgb
            tmp_rgb = sRGBColor(tmp_r, tmp_g, tmp_b, is_upscaled=True)
            lab2 = convert_color(tmp_rgb, LabColor, through_rgb_type=sRGBColor)
            eye_dic[color] = delta_e_cie1976(lab, lab2)
#            minimum = min(minimum,delta_e_cie1976(lab, lab2))
#            if minimum != flag:
#                ret = color

    elif color_type == "hair":
        for color, rgb in hairs.items():
            flag = minimum
            tmp_r, tmp_g, tmp_b = rgb
            tmp_rgb = sRGBColor(tmp_r, tmp_g, tmp_b, is_upscaled=True)
            lab2 = convert_color(tmp_rgb, LabColor, through_rgb_type=sRGBColor)
            hair_dic[color] = delta_e_cie1976(lab, lab2)
#            minimum = min(minimum,delta_e_cie1976(lab, lab2))
# if minimum != flag:
#     ret = color

    elif color_type == "skin":
        for color, rgb in skins.items():
            #            flag = minimum
            tmp_r, tmp_g, tmp_b = rgb
            tmp_rgb = sRGBColor(tmp_r, tmp_g, tmp_b, is_upscaled=True)
            lab2 = convert_color(tmp_rgb, LabColor, through_rgb_type=sRGBColor)
            skin_dic[color] = delta_e_cie1976(lab, lab2)
            # minimum = min(minimum,delta_e_cie1976(lab, lab2))
            # if minimum != flag:
            #     ret = color
    else:
        print("Wrong color type")
        exit(0)
예제 #42
0
def home():
    form =ColorSearchForm(request.form)

    # Handle search
    if request.method == 'POST':
        if form.validate_on_submit():
            return redirect(url_for("public.home") + '?color={0}'.format(form.color.data.replace('#', '')))
        else:
            flash_errors(form)

    color_results = Color.query
    max_colors = app.config['MAX_COLORS']

    color = None
    colors = None

    colors_cie2000 = None
    colors_cie1976 = None
    colors_cie1994 = None
    colors_cmc = None

    colors_cie1976_elapsed = None
    colors_cie2000_elapsed = None

    colors_cie1976_db = None
    colors_cie2000_db = None

    colors_cie1976_db_elapsed = None
    colors_cie2000_db_elapsed = None

    is_show_createschema_msg = False
    is_show_createcolors_msg = False

    if not db.engine.dialect.has_table(db.engine.connect(), 'color'):
        form = None
        is_show_createschema_msg = True
    elif (not request.args.get('color', None)) and (not color_results.count()):
        form = None
        is_show_createcolors_msg = True
    elif request.args.get('color', None):
        color = '#{0}'.format(request.args.get('color'))

        from operator import itemgetter
        from colormath.color_conversions import convert_color
        from colormath.color_objects import sRGBColor, LabColor
        from colormath.color_diff import (delta_e_cie2000,
                                          delta_e_cie1976,
                                          delta_e_cie1994,
                                          delta_e_cmc)

        from colorsearchtest.queries import (delta_e_cie1976_query,
                                             delta_e_cie2000_query)

        c_rgb = sRGBColor.new_from_rgb_hex(color)
        c_lab = convert_color(c_rgb, LabColor)

        if app.config['IS_DELTA_E_COLORMATH_ENABLED']:
            start_time = timeit.default_timer()

            colors_cie2000_tmp = []

            for c in color_results.all():
                c2_lab = LabColor(lab_l=c.lab_l,
                                  lab_a=c.lab_a,
                                  lab_b=c.lab_b,
                                  illuminant='d65')

                colors_cie2000_tmp.append({
                    'hex': str(c),
                    'fore_color': ('#{:02X}{:02X}{:02X}'.format(*calc_fore_color((c.rgb_r, c.rgb_g, c.rgb_b)))),
                    'delta_e_cie2000': delta_e_cie2000(c_lab,
                                                       c2_lab)})

            colors_cie2000 = sorted(colors_cie2000_tmp, key=itemgetter('delta_e_cie2000'))[:max_colors]

            colors_cie2000_elapsed = timeit.default_timer() - start_time

            start_time = timeit.default_timer()

            colors_cie1976_tmp = []

            for c in color_results.all():
                c2_lab = LabColor(lab_l=c.lab_l,
                                  lab_a=c.lab_a,
                                  lab_b=c.lab_b,
                                  illuminant='d65')

                colors_cie1976_tmp.append({
                    'hex': str(c),
                    'fore_color': ('#{:02X}{:02X}{:02X}'.format(*calc_fore_color((c.rgb_r, c.rgb_g, c.rgb_b)))),
                    'delta_e_cie1976': delta_e_cie1976(c_lab,
                                                       c2_lab)})

            colors_cie1976 = sorted(colors_cie1976_tmp, key=itemgetter('delta_e_cie1976'))[:max_colors]

            colors_cie1976_elapsed = timeit.default_timer() - start_time

        colors = None

        if app.config['IS_DELTA_E_DBQUERY_ENABLED']:
            start_time = timeit.default_timer()

            color_results = delta_e_cie1976_query(
                lab_l=c_lab.lab_l,
                lab_a=c_lab.lab_a,
                lab_b=c_lab.lab_b,
                limit=max_colors)

            colors_cie1976_db = []
            for c in color_results:
                colors_cie1976_db.append({
                    'hex': '#{:02X}{:02X}{:02X}'.format(c[0], c[1], c[2]),
                    'fore_color': ('#{:02X}{:02X}{:02X}'.format(*calc_fore_color((c[0], c[1], c[2])))),
                    'delta_e_cie1976_db': c[3]})

            colors_cie1976_db_elapsed = timeit.default_timer() - start_time

            start_time = timeit.default_timer()

            color_results = delta_e_cie2000_query(
                lab_l=c_lab.lab_l,
                lab_a=c_lab.lab_a,
                lab_b=c_lab.lab_b,
                limit=max_colors)

            colors_cie2000_db = []
            for c in color_results:
                colors_cie2000_db.append({
                    'hex': '#{:02X}{:02X}{:02X}'.format(c[0], c[1], c[2]),
                    'fore_color': ('#{:02X}{:02X}{:02X}'.format(*calc_fore_color((c[0], c[1], c[2])))),
                    'delta_e_cie2000_db': c[3]})

            colors_cie2000_db_elapsed = timeit.default_timer() - start_time
    else:
        colors = [{
                'hex': str(c),
                'fore_color': ('#{:02X}{:02X}{:02X}'.format(*calc_fore_color((c.rgb_r, c.rgb_g, c.rgb_b)))),
                'delta_e_cie2000': None}
            for c in color_results
                .order_by(func.random())
                .limit(max_colors)
                .all()]

    return render_template("public/home.html",
                           form=form,
                           is_show_createschema_msg=is_show_createschema_msg,
                           is_show_createcolors_msg=is_show_createcolors_msg,
                           colors=colors,
                           colors_cie2000=colors_cie2000,
                           colors_cie1976=colors_cie1976,
                           colors_cie1994=colors_cie1994,
                           colors_cmc=colors_cmc,
                           colors_cie1976_elapsed=colors_cie1976_elapsed,
                           colors_cie2000_elapsed=colors_cie2000_elapsed,
                           colors_cie1976_db=colors_cie1976_db,
                           colors_cie2000_db=colors_cie2000_db,
                           colors_cie1976_db_elapsed=colors_cie1976_db_elapsed,
                           colors_cie2000_db_elapsed=colors_cie2000_db_elapsed,
                           color=color)
 def test_cie1976_accuracy(self):
     result = delta_e_cie1976(self.color1, self.color2)
     expected = 2.151
     self.assertAlmostEqual(result, expected, 3, 
         "DeltaE CIE1976 formula error. Got %.3f, expected %.3f (diff: %.3f)." % (
             result, expected, result - expected))
예제 #44
0
    def DeltaE1976(self):
        reference = self.color1(self.lab_L, self.lab_a, self.lab_b)
        sample = self.color2(self.sam_L, self.sam_a, self.sam_b)

        return delta_e_cie1976(reference, sample)
예제 #45
0
This module shows some examples of Delta E calculations of varying types.
"""

# Does some sys.path manipulation so we can run examples in-place.
# noinspection PyUnresolvedReferences
import example_config

from colormath.color_objects import LabColor
from colormath.color_diff import delta_e_cie1976, delta_e_cie1994, \
    delta_e_cie2000, delta_e_cmc

# Reference color.
color1 = LabColor(lab_l=0.9, lab_a=16.3, lab_b=-2.22)
# Color to be compared to the reference.
color2 = LabColor(lab_l=0.7, lab_a=14.2, lab_b=-1.80)

print("== Delta E Colors ==")
print(" COLOR1: %s" % color1)
print(" COLOR2: %s" % color2)
print("== Results ==")
print(" CIE1976: %.3f" % delta_e_cie1976(color1, color2))
print(" CIE1994: %.3f (Graphic Arts)" % delta_e_cie1994(color1, color2))
# Different values for textiles.
print(" CIE1994: %.3f (Textiles)" %
      delta_e_cie1994(color1, color2, K_1=0.048, K_2=0.014, K_L=2))
print(" CIE2000: %.3f" % delta_e_cie2000(color1, color2))
# Typically used for acceptability.
print("     CMC: %.3f (2:1)" % delta_e_cmc(color1, color2, pl=2, pc=1))
# Typically used to more closely model human perception.
print("     CMC: %.3f (1:1)" % delta_e_cmc(color1, color2, pl=1, pc=1))
# white = (60, 100, 70)
# green = (6, 35, 13)
# yellow = (34, 43, 8)
# orange = (40, 20, 6)

my_white = rgb2lab((232, 232, 236))
my_green = rgb2lab((41, 202, 121))
my_white2 = rgb2lab((217, 233, 247))

print("my_white     : %s" % my_white)
print("my_green     : %s" % my_green)
print("my_white2    : %s" % my_white2)
print("my cie2000 white->green : %s" % my_delta_e_cie2000(my_white, my_green))
print("my cie2000 white->white2: %s\n\n" %
      my_delta_e_cie2000(my_white, my_white2))

white = rgb_to_labcolor(232, 232, 236)
green = rgb_to_labcolor(41, 202, 121)
white2 = rgb_to_labcolor(217, 233, 247)
distance = delta_e_cie2000(white, green)

print("white        : %s" % white)
print("green        : %s" % green)
print("white2       : %s" % white2)
print("cie2000 white->green : %s" % delta_e_cie2000(white, green))
print("cie2000 white->white2: %s\n" % delta_e_cie2000(white, white2))
print("cie1994 white->green : %s" % delta_e_cie1994(white, green))
print("cie1994 white->white2: %s\n" % delta_e_cie1994(white, white2))
print("cie1976 white->green : %s" % delta_e_cie1976(white, green))
print("cie1976 white->white2: %s\n" % delta_e_cie1976(white, white2))