Java Color Distance getDistance(int c1, Color c2)

Here you can find the source of getDistance(int c1, Color c2)

Description

get Distance

License

LGPL

Declaration

private static double getDistance(int c1, Color c2) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.*;

public class Main {
    private static double getDistance(int c1, Color c2) {
        c1 = 0xff000000 | c1;/*from w  w  w  . j  a va  2s. c o  m*/
        double rmean = ((c1 >> 16) + c2.getRed()) / 2.0;
        double r = ((c1 >> 16) & 0xFF) - c2.getRed();
        double g = ((c1 >> 8) & 0xFF) - c2.getGreen();
        int b = ((c1 >> 0) & 0xFF) - c2.getBlue();
        double weightR = 2 + rmean / 256.0;
        double weightG = 4.0;
        double weightB = 2 + (255 - rmean) / 256.0;
        return weightR * r * r + weightG * g * g + weightB * b * b;
    }
}

Related

  1. colorDistance(int r1, int g1, int b1, int r2, int g2, int b2)
  2. distance(Color a, Color b)
  3. distance(Color c1, Color c2)
  4. distanceToColor(final int distance)
  5. drawArc(Point2D start, double distance, double startAngle, double arcAngle, boolean fill, Graphics2D g2, Color color)
  6. getMaxDistance(final Color first, final Color second)
  7. pixelDistance(final Color col1, final Color col2)