Class ColorYuv

java.lang.Object
boofcv.alg.color.ColorYuv

public class ColorYuv extends Object

Color conversion between YUV and RGB, and YCbCr and RGB. YUV is color encoding which takes in account a human perception model and is commonly used in cameras/video with analog signals. YCbCr is the digital equivalent color space of YUV that is scaled and offset. YCbCr is also commonly referred to as YUV, even though it is a different format.

Y component encodes luma (B&W gray scale) and U,V encodes color. The same is true for Y,Cb,Cr, respectively. In the functions below, if the input is floating point then YUV is used, otherwise YCbCr is used. How these color formats are encoded varies widely. For YCbCr, Y is "defined to have a nominal 8-bit range of 16-235, Cb and Cr are defined to have a nominal range of 16-240", see [2].

Equations:
 Y =  0.299*R + 0.587*G + 0.114*B
 U = -0.147*R - 0.289*G + 0.436*B = 0.492*(B - Y)
 V =  0.615*R - 0.515*G - 0.100*B = 0.877*(R - Y)

Source: [1] and [2].

Citations:
  1. http://software.intel.com/sites/products/documentation/hpc/ipp/ippi/ippi_ch6/ch6_color_models.html
  2. Keith Jack, "Video Demystified" 5th ed 2007
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    rgbToYCbCr(int r, int g, int b, byte[] yuv)
    Conversion from RGB to YCbCr.
    static void
    rgbToYuv(double r, double g, double b, double[] yuv)
    Conversion from RGB to YUV using same equations as Intel IPP.
    static void
    rgbToYuv(float r, float g, float b, float[] yuv)
    Conversion from RGB to YUV using same equations as Intel IPP.
    static <T extends ImageGray<T>>
    void
    rgbToYuv(Planar<T> rgb, Planar<T> yuv)
    Convert a 3-channel Planar image from RGB into YUV.
    static int
    ycbcrToRgb(int y, int cb, int cr)
    Conversion from YCbCr to 32-bit RGB.
    static void
    ycbcrToRgb(int y, int cb, int cr, byte[] rgb)
    Conversion from YCbCr to RGB.
    static int
    yuvToRgb(double y, double u, double v)
    Conversion from YUV to 32-bit RGB using same equations as Intel IPP.
    static void
    yuvToRgb(double y, double u, double v, double[] rgb)
    Conversion from YUV to RGB using same equations as Intel IPP.
    static void
    yuvToRgb(float y, float u, float v, float[] rgb)
    Conversion from YUV to RGB using same equations as Intel IPP.
    static <T extends ImageGray<T>>
    void
    yuvToRgb(Planar<T> yuv, Planar<T> rgb)
    Convert a 3-channel Planar image from YUV into RGB.

    Methods inherited from class java.lang.Object

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

    • ColorYuv

      public ColorYuv()
  • Method Details

    • rgbToYuv

      public static void rgbToYuv(double r, double g, double b, double[] yuv)
      Conversion from RGB to YUV using same equations as Intel IPP.
    • rgbToYuv

      public static void rgbToYuv(float r, float g, float b, float[] yuv)
      Conversion from RGB to YUV using same equations as Intel IPP.
    • yuvToRgb

      public static int yuvToRgb(double y, double u, double v)
      Conversion from YUV to 32-bit RGB using same equations as Intel IPP.
    • yuvToRgb

      public static void yuvToRgb(double y, double u, double v, double[] rgb)
      Conversion from YUV to RGB using same equations as Intel IPP.
    • yuvToRgb

      public static void yuvToRgb(float y, float u, float v, float[] rgb)
      Conversion from YUV to RGB using same equations as Intel IPP.
    • rgbToYCbCr

      public static void rgbToYCbCr(int r, int g, int b, byte[] yuv)
      Conversion from RGB to YCbCr. See [Jack07].
      Parameters:
      r - Red [0 to 255]
      g - Green [0 to 255]
      b - Blue [0 to 255]
    • ycbcrToRgb

      public static int ycbcrToRgb(int y, int cb, int cr)
      Conversion from YCbCr to 32-bit RGB. See [Jack07].
      Parameters:
      y - Y [0 to 255]
      cb - Cb [0 to 255]
      cr - Cr [0 to 255]
    • ycbcrToRgb

      public static void ycbcrToRgb(int y, int cb, int cr, byte[] rgb)
      Conversion from YCbCr to RGB. See [Jack07].
      Parameters:
      y - Y [0 to 255]
      cb - Cb [0 to 255]
      cr - Cr [0 to 255]
    • yuvToRgb

      public static <T extends ImageGray<T>> void yuvToRgb(Planar<T> yuv, Planar<T> rgb)
      Convert a 3-channel Planar image from YUV into RGB. If integer then YCbCr and not YUV.
      Parameters:
      rgb - (Input) RGB encoded image
      yuv - (Output) YUV encoded image
    • rgbToYuv

      public static <T extends ImageGray<T>> void rgbToYuv(Planar<T> rgb, Planar<T> yuv)
      Convert a 3-channel Planar image from RGB into YUV. If integer then YCbCr and not YUV. NOTE: Input and output image can be the same instance.
      Parameters:
      rgb - (Input) RGB encoded image
      yuv - (Output) YUV encoded image