Here you can find the source of rgbToGrey(byte[] rgb)
Parameter | Description |
---|---|
rgb | a parameter |
public static byte[] rgbToGrey(byte[] rgb)
//package com.java2s; /*//from w w w .j a va 2 s.com ColorMapUtils.java (c) 2011-2013 Edward Swartz All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Return a grey RGB triplet corresponding to the luminance * of the incoming color RGB triplet. * @param rgb * @return */ public static byte[] rgbToGrey(byte[] rgb) { byte[] g = new byte[3]; int lum = getRGBLum(rgb); g[0] = g[1] = g[2] = (byte) lum; return g; } public static void rgbToGrey(int[] rgb, int[] g) { int lum = getRGBLum(rgb); g[0] = g[1] = g[2] = lum; } public static void rgbToGrey(byte[] rgb, byte[] g) { int lum = getRGBLum(rgb); g[0] = g[1] = g[2] = (byte) lum; } /** * @param rgb * @return */ public static int getRGBLum(byte[] rgb) { int plum = (299 * (rgb[0] & 0xff) + 587 * (rgb[1] & 0xff) + 114 * (rgb[2] & 0xff)) / 1000; return plum; } /** * @param prgb * @return */ public static int getRGBLum(int[] prgb) { int lum = (299 * (prgb[0] & 0xff) + 587 * (prgb[1] & 0xff) + 114 * (prgb[2] & 0xff)) / 1000; return lum; } }