def test_cmc(): data = load_ciede2000_data() N = len(data) lab1 = np.zeros((N, 3)) lab1[:, 0] = data['L1'] lab1[:, 1] = data['a1'] lab1[:, 2] = data['b1'] lab2 = np.zeros((N, 3)) lab2[:, 0] = data['L2'] lab2[:, 1] = data['a2'] lab2[:, 2] = data['b2'] dE2 = deltaE_cmc(lab1, lab2) oracle = np.array([ 1.73873611, 2.49660844, 3.30494501, 0.85735576, 0.88332927, 0.97822692, 3.50480874, 2.87930032, 6.5783807, 6.57838075, 6.5783808, 6.57838086, 6.67492321, 6.67492326, 6.67492331, 4.66852997, 42.10875485, 39.45889064, 38.36005919, 33.93663807, 1.14400168, 1.00600419, 1.11302547, 1.05335328, 1.42822951, 1.2548143, 1.76838061, 2.02583367, 3.08695508, 1.74893533, 1.90095165, 1.70258148, 1.80317207, 2.44934417 ]) assert_allclose(dE2, oracle, rtol=1.e-8)
def __create_col__(self,i,j): i_start,i_end,j_start,j_end = (i*self.n_col,(i+1)*self.n_col,j*self.m_col,(j+1)*self.m_col) slze = self.img_in[i_start:i_end,j_start:j_end] slze = color.rgb2lab(slze) DISTS=[np.mean(color.deltaE_cmc(slze,img)) for img in self.col_images_array]#Calculate "differences" best_col = np.nanargmin(DISTS) self.img_out[i_start:i_end,j_start:j_end]=self.col_images_array[best_col]
def color_diff(rgb1, rgb2): """ Calculate distance between two RGB colors. See discussion: http://stackoverflow.com/questions/8863810/python-find-similar-colors-best-way - for basic / fast calculations, you can use dE76 but beware of its problems - for graphics arts use we recommend dE94 and perhaps dE-CMC 2:1 - for textiles use dE-CMC """ rgb1 = np.array(rgb1, dtype="float64").reshape(1, 1, 3) / 255.0 rgb2 = np.array(rgb2, dtype="float64").reshape(1, 1, 3) / 255.0 lab1 = rgb2lab(rgb1) lab2 = rgb2lab(rgb2) return deltaE_cmc(lab1, lab2, kL=2, kC=1)[0, 0]
def color_diff(rgb1, rgb2): """ Calculate distance between two RGB colors. See discussion: http://stackoverflow.com/questions/8863810/python-find-similar-colors-best-way - for basic / fast calculations, you can use dE76 but beware of its problems - for graphics arts use we recommend dE94 and perhaps dE-CMC 2:1 - for textiles use dE-CMC """ import numpy as np from skimage.color import rgb2lab, deltaE_cmc rgb1 = np.array(rgb1, dtype="float64").reshape(1, 1, 3) / 255. rgb2 = np.array(rgb2, dtype="float64").reshape(1, 1, 3) / 255. lab1 = rgb2lab(rgb1) lab2 = rgb2lab(rgb2) return deltaE_cmc(lab1, lab2, kL=2, kC=1)[0, 0]
def delta_filter(self, l, a, b): interval = 3 s = l.size-1 t_row = np.zeros((1, s)) for j in range(1,interval): c_int = j for x in range(0, s): r_row = np.zeros((1,s)) if x-c_int > 0: i1 = x-c_int else: i1 = 0 if x+c_int > s: i2 = s else: i2 = x+c_int l1 = np.mean(l.take([i1, x])) l2 = np.mean(l.take([x, i2])) a1 = np.mean(a.take([i1, x])) a2 = np.mean(a.take([x, i2])) b1 = np.mean(b.take([i1, x])) b2 = np.mean(b.take([x, i2])) dE = color.deltaE_cmc([l1, a1, b1], [l2, a2, b2]) if not math.isnan(dE): np.put(r_row, range(i1, i2), dE) t_row = np.add(t_row, r_row) return t_row
def test_single_color_cmc(): lab1 = (0.5, 0.5, 0.5) lab2 = (0.4, 0.4, 0.4) deltaE_cmc(lab1, lab2)
def get_delta(pic): print(color.deltaE_cmc(LabPic, pic)[0][0]) print(color.deltaE_ciede94(LabPic, pic)[0][0]) print(color.deltaE_ciede2000(LabPic, pic)[0][0])
def distance_cmc(src_lab, dst_lab): return color.deltaE_cmc(src_lab, dst_lab)
# quadrant. # <codecell> from skimage import img_as_float image = img_as_float(io.imread('../images/color-wheel.jpg')) blue_lab = color.rgb2lab([[[0, 0, 1.]]]) light_blue_lab = color.rgb2lab([[[0, 1, 1.]]]) red_lab = color.rgb2lab([[[1, 0, 0.]]]) image_lab = color.rgb2lab(image) distance_blue = color.deltaE_cmc(blue_lab, image_lab, kL=0.5, kC=0.5) distance_light_blue = color.deltaE_cmc(light_blue_lab, image_lab, kL=0.5, kC=0.5) distance_red = color.deltaE_cmc(red_lab, image_lab, kL=0.5, kC=0.5) distance = distance_blue + distance_light_blue - distance_red distance = exposure.rescale_intensity(distance) image_blue = image.copy() image_blue[distance > 0.3] = 0 f, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(10, 5)) ax0.imshow(image) ax1.imshow(distance, cmap='gray') ax2.imshow(image_blue) plt.show()