Here you can find the source of pixelDistance(final Color col1, final Color col2)
Parameter | Description |
---|---|
col1 | first color |
col2 | second color |
private static double pixelDistance(final Color col1, final Color col2)
//package com.java2s; /**// w w w . j av a 2 s. c o m * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Color; public class Main { /** * Calculates the distance between two colors. * @param col1 first color * @param col2 second color * @return distance between col1 and col2 */ private static double pixelDistance(final Color col1, final Color col2) { int r1 = col1.getRed(); int g1 = col1.getGreen(); int b1 = col1.getBlue(); int r2 = col2.getRed(); int g2 = col2.getGreen(); int b2 = col2.getBlue(); double pixelDistance = Math .sqrt(((r1 - r2) * (r1 - r2)) + ((g1 - g2) * (g1 - g2)) + ((b1 - b2) * (b1 - b2))); return pixelDistance; } }