Here you can find the source of colorDistance(int r1, int g1, int b1, int r2, int g2, int b2)
private static double colorDistance(int r1, int g1, int b1, int r2, int g2, int b2)
//package com.java2s; public class Main { private static double colorDistance(int r1, int g1, int b1, int r2, int g2, int b2) { double rmean = (r1 + r2) / 2; int r = r1 - r2; int g = g1 - g2; int b = b1 - b2; double weightR = 2 + rmean / 256; double weightG = 4.0; double weightB = 2 + (255 - rmean) / 256; return Math.sqrt(weightR * r * r + weightG * g * g + weightB * b * b); }/*from w w w .ja va2 s . c o m*/ }