Java RGB Color Convert To rgb2xyz(double[] RGB)

Here you can find the source of rgb2xyz(double[] RGB)

Description

Converts from the given RGB triplet into a corresponding XYZ triplet.

License

GNU General Public License

Parameter

Parameter Description
RGB red, green and blue components, in the range from 0 to 1

Return

the XYZ color components

Declaration

public static double[] rgb2xyz(double[] RGB) 

Method Source Code

//package com.java2s;
/***************************************
 *            ViPER                    *
 *  The Video Processing               *
 *         Evaluation Resource         *
 *                                     *
 *  Distributed under the GPL license  *
 *        Terms available at gnu.org.  *
 *                                     *
 *  Copyright University of Maryland,  *
 *                      College Park.  *
 ***************************************/

public class Main {
    /**//from  ww w . j  ava 2  s. com
     * Converts from the given RGB triplet into a corresponding
     * XYZ triplet.
     * @param RGB red, green and blue components, in the range from 0 to 1
     * @return the XYZ color components
     */
    public static double[] rgb2xyz(double[] RGB) {
        double[] xyz = new double[3];
        double[] rgb = new double[3];
        System.arraycopy(RGB, 0, rgb, 0, 3);
        for (int i = 0; i < 3; i++) {
            if (rgb[i] > 0.04045) {
                rgb[i] = Math.pow((rgb[i] + 0.055) / 1.055, 2.4);
            } else {
                rgb[i] = rgb[i] / 12.92;
            }
        }

        xyz[0] = rgb[0] * 0.4124 + rgb[1] * 0.3576 + rgb[2] * 0.1805;
        xyz[1] = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722;
        xyz[2] = rgb[0] * 0.0193 + rgb[1] * 0.1192 + rgb[2] * 0.9505;
        return xyz;
    }
}

Related

  1. rgb2hsv(int r, int g, int b)
  2. rgb2int(final int[] color)
  3. rgb2intval(int r, int g, int b)
  4. rgb2lab(int R, int G, int B)
  5. rgb2luv(double[] rgb, double[] luv)
  6. rgb2xyz(double[] rgb, double[] xyz)
  7. RGB2YCbCr(int r, int g, int b, boolean useBT601)
  8. RGB2YCbCr(int[] rgb, float[][] Y, float[][] Cb, float[][] Cr, int imageWidth, int imageHeight)
  9. rgb2yuv(float r, float g, float b, float[] yuv)