perceptual Euclidean color distance
196613
function distEuclidean(rgb0, rgb1) {
		var rd = rgb1[0]-rgb0[0],
			gd = rgb1[1]-rgb0[1],
			bd = rgb1[2]-rgb0[2];

		return Math.sqrt(Pr*rd*rd + Pg*gd*gd + Pb*bd*bd) / euclMax;
	}
786420
function(red, green, blue, model) {
    red = red / 255;
    green = green / 255;
    blue = blue / 255;
    var r = red > 0.04045 ? Math.pow(((red + 0.055) / 1.055), 2.4000000953674316) : red / 12.92;
    var g = green > 0.04045 ? Math.pow(((green + 0.055) / 1.055), 2.4000000953674316) : green / 12.92;
    var b = blue > 0.04045 ? Math.pow(((blue + 0.055) / 1.055), 2.4000000953674316) : blue / 12.92;
    var x = r * 0.664511 + g * 0.154324 + b * 0.162028;
    var y = r * 0.283881 + g * 0.668433 + b * 0.047685;
    var z = r * 8.8E-5 + g * 0.07231 + b * 0.986039;
    var xy = [x / (x + y + z), y / (x + y + z)];
    if (isNaN(xy[0])) {
      xy[0] = 0.0;
    }
    
    if (isNaN(xy[1])) {
      xy[1] = 0.0;
    }
    
    var colorPoints = colorPointsForModel(model);
    var inReachOfLamps = checkPointInLampsReach(xy, colorPoints);
    if (!inReachOfLamps) {
      var pAB = getClosestPointToPoints(colorPoints[0], colorPoints[1], xy);
      var pAC = getClosestPointToPoints(colorPoints[2], colorPoints[0], xy);
      var pBC = getClosestPointToPoints(colorPoints[1], colorPoints[2], xy);
      var dAB = getDistanceBetweenTwoPoints(xy, pAB);
      var dAC = getDistanceBetweenTwoPoints(xy, pAC);
      var dBC = getDistanceBetweenTwoPoints(xy, pBC);
      var lowest = dAB;
      var closestPoint = pAB;
      if (dAC < dAB) {
        lowest = dAC;
        closestPoint = pAC;
      }
      
      if (dBC < lowest) {
        closestPoint = pBC;
      }
      
      xy[0] = closestPoint[0];
      xy[1] = closestPoint[1];
    }
    
    xy[0] = precision(xy[0]);
    xy[1] = precision(xy[1]);
    return xy;
  }
467060
function optimizeHistogram(histogram, options) {
  options = _.defaults(options || {}, {
    colorDistanceThreshold: 22
  });

  for (var i = 0; i < histogram.length - 1; i++) {
    if (histogram[i].count === 0) {
      continue;
    }

    for (var j = i + 1; j < histogram.length; j++) {
      var distance = getColorDistance(histogram[i].color, histogram[j].color);

      if (distance <= options.colorDistanceThreshold) {
        histogram[i].count += histogram[j].count;
        histogram[j].count = 0;
      }
    }
  }

  histogram = _.filter(histogram, function (group) {
    return group.count > 0;
  });

  return sortByCountDesc(histogram);
}
517424
function colorBlend(mode, color1, color2) {
    var ab = color1.alpha, cb, // backdrop
        as = color2.alpha, cs, // source
        ar, cr, r = [];        // result

    ar = as + ab * (1 - as);
    for (var i = 0; i < 3; i++) {
        cb = color1.rgb[i] / 255;
        cs = color2.rgb[i] / 255;
        cr = mode(cb, cs);
        if (ar) {
            cr = (as * cs + ab * (cb
                - as * (cb + cs - cr))) / ar;
        }
        r[i] = cr * 255;
    }

    return new(tree.Color)(r, ar);
}
471803
private static double similarity(BufferedImage var, BufferedImage cont) {
		
		double[] varArr = new double[var.getWidth()*var.getHeight()*3];
		double[] contArr = new double[cont.getWidth()*cont.getHeight()*3];
		
		if (varArr.length!=contArr.length)
			throw new IllegalStateException("The pictures are different sizes!");
		
		//unroll pixels
		for(int i = 0; i < var.getHeight(); i++) {
			for(int j = 0; j < var.getWidth(); j++) {
				varArr[i*var.getWidth() + j + 0] = new Color(var.getRGB(j, i)).getRed();
				contArr[i*cont.getWidth() + j + 0] = new Color(cont.getRGB(j, i)).getRed();
				varArr[i*var.getWidth() + j + 1] = new Color(var.getRGB(j, i)).getGreen();
				contArr[i*cont.getWidth() + j + 1] = new Color(cont.getRGB(j, i)).getGreen();
				varArr[i*var.getWidth() + j + 2] = new Color(var.getRGB(j, i)).getBlue();
				contArr[i*cont.getWidth() + j + 2] = new Color(cont.getRGB(j, i)).getBlue();
			}
		}

		double mins=0;
		double maxs=0;
		for(int i=0;i!=varArr.length;i++){
			if (varArr[i]>contArr[i]){
				mins+=contArr[i];
				maxs+=varArr[i];
			} else {
				mins+=varArr[i];
				maxs+=contArr[i];
			}
		}
		return mins/maxs;
	}
827825
def _sim_colour(r1, r2):
    
    return sum([min(a, b) for a, b in zip(r1["hist_c"], r2["hist_c"])])
74607
def calc_signal_color1(self, distance_modulus, mass_steps=10000):
        
        mag_1, mag_2 = self.catalog.mag_1,self.catalog.mag_2
        mag_err_1, mag_err_2 = self.catalog.mag_err_1,self.catalog.mag_err_2
        u_density = self.isochrone.pdf(mag_1,mag_2,mag_err_1,mag_err_2,distance_modulus,self.delta_mag,mass_steps)

        #u_color = u_density * self.delta_mag**2
        u_color = u_density

        return u_color
283517
def rgb_reduce(r, g, b, mode=8):
    '''
    
    '''
    colours = ANSI_COLOURS[:mode]
    matches = [(rgb_distance(c, map(int, [r, g, b])), i)
        for i, c in enumerate(colours)]
    matches.sort()
    return sequence('m')(str(30 + matches[0][1]))
440195
def rgb2gray(img):
    """"""
    T = np.linalg.inv(np.array([
        [1.0,  0.956,  0.621],
        [1.0, -0.272, -0.647],
        [1.0, -1.106,  1.703],
    ]))
    r_c, g_c, b_c = T[0]
    r, g, b = np.rollaxis(as_float_image(img), axis=-1)
    return r_c * r + g_c * g + b_c * b
1111788
def from_floats(red, green, blue):
        """"""

        return Color(int(red * Color.MAX_VALUE),
                     int(green * Color.MAX_VALUE),
                     int(blue * Color.MAX_VALUE))
423623
public static int contrast(Color left, Color right) throws ServletException {
	return (Math.max(left.getRed(), right.getRed()) - Math.min(left.getRed(), right.getRed()))
		+ (Math.max(left.getGreen(), right.getGreen()) - Math.min(left.getGreen(), right.getGreen()))
		+ (Math.max(left.getBlue(), right.getBlue()) - Math.max(left.getBlue(), right.getBlue()));
    }
904754
def _svgcolor(color):
    
    return 'rgb(%d,%d,%d)' % tuple([int(255 * x) for x in [color.r, color.g, color.b]])
136417
def rgb2gray(rgb):
    

    w = sla.atleast_nd(rgb.ndim, np.array([0.299, 0.587, 0.144],
                                          dtype=rgb.dtype, ndmin=3))
    return np.sum(w * rgb, axis=2)
464772
def similarity( color1, color2, ignore_lightness: false )
      l1, a1, b1 = *rgb2lab(color1.to_rgb)
      l2, a2, b2 = *rgb2lab(color2.to_rgb)
      Math.sqrt( (ignore_lightness ? 0 : (l1-l2)**2) + (a1-a2)**2 + (b1-b2)**2 )
    end
946167
def laplacian_of_gaussian(image, mask, size, sigma):
    '''
    '''
    half_size = size//2
    i,j = np.mgrid[-half_size:half_size+1,
                   -half_size:half_size+1].astype(float) / float(sigma)
    distance = (i**2 + j**2)/2
    gaussian = np.exp(-distance)
    #
    # Normalize the Gaussian
    #
    gaussian = gaussian / np.sum(gaussian)

    log = (distance - 1) * gaussian
    #
    # Normalize the kernel to have a sum of zero
    #
    log = log - np.mean(log)
    if mask is None:
        mask = np.ones(image.shape[:2], bool)
    masked_image = image.copy()
    masked_image[~mask] = 0
    output = convolve(masked_image, log, mode='constant', cval=0)
    #
    # Do the LoG of the inverse of the mask. This finds the magnitude of the
    # contribution of the masked pixels. We then fudge by multiplying by the
    # value at the pixel of interest - this effectively sets the value at a
    # masked pixel to that of the pixel of interest.
    #
    # It underestimates the LoG, that's not a terrible thing.
    #
    correction = convolve((~ mask).astype(float), log, mode='constant', cval = 1)
    output += correction * image
    output[~ mask] = image[~ mask]
    return output
190872
def euclidian other_color
      # TODO: different depths
      r  = (self.r.to_i - other_color.r.to_i)**2
      r += (self.g.to_i - other_color.g.to_i)**2
      r += (self.b.to_i - other_color.b.to_i)**2
      Math.sqrt r
    end
658597
def diff_colormap():
    ""

    # bottom = plt.cm.copper(np.linspace(0., 1, 6))
    black = np.atleast_2d([0., 0., 0., 1.])
    bottom = np.repeat(black, 6, axis=0)
    middle = plt.cm.copper(np.linspace(0, 1, 250))
    # remain = plt.cm.Reds(np.linspace(0, 1, 240))

    colors = np.vstack((bottom, middle))
    diff_colormap = mpl.colors.LinearSegmentedColormap.from_list('diff_colormap', colors)

    return diff_colormap