Here you can find the source of rgbDistance(int color1, int color2)
Parameter | Description |
---|---|
color1 | a parameter |
color2 | a parameter |
private static double rgbDistance(int color1, int color2)
//package com.java2s; /* //from w ww . ja v a2s . c om * SMART FP7 - Search engine for MultimediA enviRonment generated contenT * Webpage: http://smartfp7.eu * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * The Original Code is Copyright (c) 2012-2013 the University of Glasgow * All Rights Reserved * * Contributor(s): * Dyaa Albakour <dyaa.albakour@glasgow.ac.uk> */ public class Main { /** * Get the Euclidean distance between two colors. * * @param color1 * @param color2 * @return */ private static double rgbDistance(int color1, int color2) { int[] c1, c2; c1 = decode(color1); c2 = decode(color2); return Math.pow(c1[0] - c2[0], 2) + Math.pow(c1[1] - c2[1], 2) + Math.pow(c1[2] - c2[2], 2); } /** * Decode a color into its RGB components. * @param color * @return */ public static int[] decode(int color) { int r = color / (256 * 256); int g = color / (256); int b = color % 256; return new int[] { r, g, b }; } }