Class ColorXyz

java.lang.Object
boofcv.alg.color.ColorXyz

public class ColorXyz
extends Object

Color conversion between RGB and CIE XYZ models.

RGB is the standard 8-bit RGB format. It is first converted to an intermediate linear RGB format (gamma(double) and invGamma(double)) that can be converted into XYZ using a linear equation.

XYZ color space is an international standard developed by the CIE (Commission Internationale de l’Eclairage). This model is based on three hypothetical primaries, XYZ, and all visible colors can be represented by using only positive values of X, Y, and Z. The CIE XYZ primaries are hypothetical because they do not correspond to any real light wavelengths. The Y primary is intentionally defined to match closely to luminance, while X and Z primaries give color information. The main advantage of the CIE XYZ space (and any color space based on it) is that this space is completely device-independent.

The above text is and equations below are copied from [1], which cites [2] as their source.

Linear RGB explained: The luminance intensity generated by most displays is not a linear function of the applied signal but is proportional to some power (referred to as gamma) of the signal voltage. As a result, high intensity ranges are expanded and low intensity ranges are compressed. This nonlinearity must be compensated to achieve correct color reproduction. To do this, luminance of each of the linear red, green, and blue components is reduced to a nonlinear form using an inverse transformation. This process is called "gamma correction". See [3]

  1. Intel IPP Color Models
  2. David Rogers. Procedural Elements for Computer Graphics. McGraw-Hill, 1985.
  3. Intel IPP Gamma Correction
  • Field Summary

    Fields
    Modifier and Type Field Description
    static double[] table_invgamma_d  
    static float[] table_invgamma_f  
  • Constructor Summary

    Constructors
    Constructor Description
    ColorXyz()  
  • Method Summary

    Modifier and Type Method Description
    static double gamma​(double v)
    Forward gamma correction function
    static double invGamma​(double v)
    Inverse gamma correction function
    static void linearRgbToXyz​(double r, double g, double b, double[] xyz)
    Conversion from gamma corrected Linear RGB into CEI XYZ.
    static void linearRgbToXyz​(float r, float g, float b, float[] xyz)
    Conversion from gamma corrected Linear RGB into CEI XYZ.
    static void rgbToXyz​(double r, double g, double b, float[] xyz)
    Conversion from 8-bit RGB into XYZ.
    static void rgbToXyz​(int r, int g, int b, double[] xyz)
    Conversion from 8-bit RGB into XYZ.
    static void rgbToXyz​(int r, int g, int b, float[] xyz)
    Conversion from 8-bit RGB into XYZ.
    static <T extends ImageGray<T>>
    void
    rgbToXyz​(Planar<T> rgb, Planar<GrayF32> xyz)
    Convert a Planar 8-bit RGB into XYZ.
    static void xyzToLinearRgb​(double x, double y, double z, double[] linearRgb)
    Conversion from CEI XYZ to gamma corrected Linear RGB.
    static void xyzToLinearRgb​(float x, float y, float z, float[] linearRgb)
    Conversion from CEI XYZ to gamma corrected Linear RGB.
    static void xyzToRgb​(double x, double y, double z, double[] linearRgb, int[] rgb)
    Conversion of CEI XYZ to 8-bit RGB.
    static void xyzToRgb​(float x, float y, float z, float[] linearRgb, float[] rgb)
    Conversion of CEI XYZ to 8-bit RGB.
    static void xyzToRgb​(float x, float y, float z, float[] linearRgb, int[] rgb)
    Conversion of CEI XYZ to 8-bit RGB.
    static <T extends ImageGray<T>>
    void
    xyzToRgb​(Planar<GrayF32> xyz, Planar<T> rgb)
    Converts a Planar CEI XYZ image to 8-bit RGB.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • table_invgamma_f

      public static final float[] table_invgamma_f
    • table_invgamma_d

      public static final double[] table_invgamma_d
  • Constructor Details

    • ColorXyz

      public ColorXyz()
  • Method Details

    • rgbToXyz

      public static void rgbToXyz​(int r, int g, int b, double[] xyz)
      Conversion from 8-bit RGB into XYZ. 8-bit = range of 0 to 255.
    • rgbToXyz

      public static void rgbToXyz​(int r, int g, int b, float[] xyz)
      Conversion from 8-bit RGB into XYZ. 8-bit = range of 0 to 255.
    • rgbToXyz

      public static void rgbToXyz​(double r, double g, double b, float[] xyz)
      Conversion from 8-bit RGB into XYZ. 8-bit = range of 0 to 255.
    • xyzToRgb

      public static void xyzToRgb​(double x, double y, double z, double[] linearRgb, int[] rgb)
      Conversion of CEI XYZ to 8-bit RGB. Converts to Linear RGB and then applies gamma correction.
      Parameters:
      linearRgb - (output) Workspace to store intermediate linearRgb results
      rgb - (output) Output of gamma corrected RGB color 0 to 255
    • xyzToRgb

      public static void xyzToRgb​(float x, float y, float z, float[] linearRgb, int[] rgb)
      Conversion of CEI XYZ to 8-bit RGB. Converts to Linear RGB and then applies gamma correction.
      Parameters:
      linearRgb - (output) Workspace to store intermediate linearRgb results
      rgb - (output) Output of gamma corrected RGB color 0 to 255
    • xyzToRgb

      public static void xyzToRgb​(float x, float y, float z, float[] linearRgb, float[] rgb)
      Conversion of CEI XYZ to 8-bit RGB. Converts to Linear RGB and then applies gamma correction.
      Parameters:
      linearRgb - (output) Workspace to store intermediate linearRgb results
      rgb - (output) Output of gamma corrected RGB color.
    • invGamma

      public static double invGamma​(double v)
      Inverse gamma correction function
    • gamma

      public static double gamma​(double v)
      Forward gamma correction function
    • linearRgbToXyz

      public static void linearRgbToXyz​(double r, double g, double b, double[] xyz)
      Conversion from gamma corrected Linear RGB into CEI XYZ. Normalized RGB values have a range of 0:1
    • linearRgbToXyz

      public static void linearRgbToXyz​(float r, float g, float b, float[] xyz)
      Conversion from gamma corrected Linear RGB into CEI XYZ. Normalized RGB values have a range of 0:1
    • xyzToLinearRgb

      public static void xyzToLinearRgb​(float x, float y, float z, float[] linearRgb)
      Conversion from CEI XYZ to gamma corrected Linear RGB. Normalized RGB values have a range of 0:1
    • xyzToLinearRgb

      public static void xyzToLinearRgb​(double x, double y, double z, double[] linearRgb)
      Conversion from CEI XYZ to gamma corrected Linear RGB. Normalized RGB values have a range of 0:1
    • rgbToXyz

      public static <T extends ImageGray<T>> void rgbToXyz​(Planar<T> rgb, Planar<GrayF32> xyz)
      Convert a Planar 8-bit RGB into XYZ. NOTE: Input and output image can be the same instance.
      Parameters:
      rgb - (Input) RGB encoded image. R = channel 0, G = channel 1, B = channel 2
      xyz - (Output) 8-bit XYZ encoded image. X = channel 0, Y = channel 1, Z = channel 2
    • xyzToRgb

      public static <T extends ImageGray<T>> void xyzToRgb​(Planar<GrayF32> xyz, Planar<T> rgb)
      Converts a Planar CEI XYZ image to 8-bit RGB. NOTE: Input and output image can be the same instance.
      Parameters:
      xyz - (Input) XYZ encoded image. X = channel 0, Y = channel 1, Z = channel 2
      rgb - (Output) 8-bit RGB encoded image. R = channel 0, G = channel 1, B = channel 2