Here you can find the source of colorDistance(final double r1, final double g1, final double b1, final double r2, final double g2, final double b2)
public static double colorDistance(final double r1, final double g1, final double b1, final double r2, final double g2, final double b2)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww . j a va2 s .c o m * Return the "distance" between two colors. The rgb entries are taken * to be coordinates in a 3D space [0.0-1.0], and this method returnes * the distance between the coordinates for the first and second color. * * @return Distance between colors. */ public static double colorDistance(final double r1, final double g1, final double b1, final double r2, final double g2, final double b2) { double a = r2 - r1; double b = g2 - g1; double c = b2 - b1; return Math.sqrt(a * a + b * b + c * c); } /** * Return the "distance" between two colors. * * @param color1 First color [r,g,b]. * @param color2 Second color [r,g,b]. * @return Distance bwetween colors. */ public static double colorDistance(final int color1, final int color2) { int[] rgb1 = int2rgb(color1), rgb2 = int2rgb(color2); return colorDistance(rgb1[0] / 256.0d, rgb1[1] / 256.0d, rgb1[2] / 256.0d, rgb2[0] / 256.0d, rgb2[1] / 256.0d, rgb2[2] / 256.0d); } public static int[] int2rgb(final int color) { return new int[] { (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF }; } }