Java Utililty Methods Color Distance

List of utility methods to do Color Distance

Description

The list of methods to do Color Distance are organized into topic(s).

Method

floatcolorDiff(int a, int b)
Calculates the difference between two colors.
int ar = a & 0xFF;
int ag = (a >> 8) & 0xFF;
int ab = (a >> 16) & 0xFF;
int aa = (a >> 24) & 0xFF;
int br = a & 0xFF;
int bg = (a >> 8) & 0xFF;
int bb = (a >> 16) & 0xFF;
int ba = (a >> 24) & 0xFF;
...
intcolorDiffAlpha(int a, int b)
color Diff Alpha
int ar = a & 0xFF;
int ag = (a >> 8) & 0xFF;
int ab = (a >> 16) & 0xFF;
int aa = (a >> 24) & 0xFF;
int br = a & 0xFF;
int bg = (a >> 8) & 0xFF;
int bb = (a >> 16) & 0xFF;
int ba = (a >> 24) & 0xFF;
...
floatcolordiffsq(int rgb0, int rgb1)
Computes squared euclidian distance of two RGB color values.
final int rDist = getRed(rgb0) - getRed(rgb1);
final int gDist = getGreen(rgb0) - getGreen(rgb1);
final int bDist = getBlue(rgb0) - getBlue(rgb1);
return rDist * rDist + gDist * gDist + bDist * bDist;
doublecolorDistance(double r1, double g1, double b1, double r2, double g2, double b2)
Simple Color Distance.
double a = r2 - r1;
double b = g2 - g1;
double c = b2 - b1;
return Math.sqrt(a * a + b * b + c * c);
doublecolorDistance(final double r1, final double g1, final double b1, final double r2, final double g2, final double b2)
Return the "distance" between two colors.
double a = r2 - r1;
double b = g2 - g1;
double c = b2 - b1;
return Math.sqrt(a * a + b * b + c * c);
floatcolorDistance(final float[] lab1, final float[] lab2)
Computes the distance E (CIE 1994) between two colors in LAB color space.
double sum = 0;
for (int i = Math.min(lab1.length, lab2.length); --i >= 0;) {
    final double delta = lab1[i] - lab2[i];
    sum += delta * delta;
return (float) Math.sqrt(sum);
floatcolorDistance(final float[] lab1, final float[] lab2)
Computes the distance E (CIE 1994) between two colors in LAB color space.
double sum;
if (false) {
    final double dL = (double) lab1[0] - lab2[0];
    final double da = (double) lab1[1] - lab2[1];
    final double db = (double) lab1[2] - lab2[2];
    final double C1 = Math.hypot(lab1[1], lab1[2]);
    final double C2 = Math.hypot(lab2[1], lab2[2]);
    final double dC = C1 - C2;
...
doublecolorDistance(int r1, int g1, int b1, int r2, int g2, int b2)
color Distance
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);
...
intdistance(Color a, Color b)
color distance
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();
...
doubledistance(Color c1, Color c2)
distance
float[] rgb1 = c1.getRGBColorComponents(null);
float[] rgb2 = c2.getRGBColorComponents(null);
double x = rgb2[0] - rgb1[0];
double y = rgb2[1] - rgb1[1];
double z = rgb2[2] - rgb1[2];
return Math.sqrt(x * x + y * y + z * z);