Here you can find the source of distance(Color a, Color b)
public static int distance(Color a, Color b)
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { /**//from www .ja va 2 s . c om * color distance */ public static int distance(Color a, Color b) { int dist = 0; int delta = a.getRed() - b.getRed(); dist += delta * delta; delta = a.getGreen() - b.getGreen(); dist += delta * delta; delta = a.getBlue() - b.getBlue(); dist += delta * delta; delta = a.getAlpha() - b.getAlpha(); dist += delta * delta; return dist; } }