Class ColorHsv

java.lang.Object
boofcv.alg.color.ColorHsv

public class ColorHsv
extends Object

Color conversion between RGB and HSV color spaces. HSV stands for Hue-Saturation-Value. "Hue" has a range of [0,2*PI] and "Saturation" has a range of [0,1], the two together represent the color. While "Value" has the same range as the input pixels and represents how light/dark the color is. Original algorithm taken from [1] and modified slightly.

NOTE: The hue is represented in radians instead of degrees, as is often done.
NOTE: Hue will be set to NaN if it is undefined. It is undefined when chroma is zero, which happens when the input color is a pure gray (e.g. same value across all color bands).

RGB to HSV:

 min = min(r,g,b)
 max = max(r,g,b)
 delta = max-min  // this is the chroma
 value = max

 if( max != 0 )
   saturation = delta/max
 else
   saturation = 0;
   hue = NaN

 if( r == max )
   hue = (g-b)/delta
 else if( g == max )
   hue = 2 + (b-r)/delta
 else
   hue = 4 + (r-g)/delta

 hue *= 60.0*PI/180.0
 if( hue < 0 )
   hue += 2.0*PI

 

[1] http://www.cs.rit.edu/~ncs/color/t_convert.html

  • Field Summary

    Fields
    Modifier and Type Field Description
    static float d60_F32  
    static double d60_F64  
    static float PI2_F32  
    static double PI2_F64  
  • Constructor Summary

    Constructors
    Constructor Description
    ColorHsv()  
  • Method Summary

    Modifier and Type Method Description
    static int hsvToRgb​(double h, double s, double v)
    Convert HSV color into 32-bit int RGB color
    static void hsvToRgb​(double h, double s, double v, double[] rgb)
    Convert HSV color into RGB color
    static void hsvToRgb​(float h, float s, float v, float[] rgb)
    Convert HSV color into RGB color
    static <T extends ImageGray<T>>
    void
    hsvToRgb​(Planar<T> hsv, Planar<T> rgb)
    Converts an image from HSV into RGB.
    static void rgbToHsv​(double r, double g, double b, double[] hsv)
    Convert RGB color into HSV color
    static void rgbToHsv​(float r, float g, float b, float[] hsv)
    Convert RGB color into HSV color
    static <T extends ImageGray<T>>
    void
    rgbToHsv​(Planar<T> rgb, Planar<T> hsv)
    Converts an image from RGB into HSV.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • ColorHsv

      public ColorHsv()
  • Method Details

    • hsvToRgb

      public static int hsvToRgb​(double h, double s, double v)
      Convert HSV color into 32-bit int RGB color
      Parameters:
      h - Hue [0,2*PI]
      s - Saturation [0,1]
      v - Value. Assumes to have a range of 0 to 255
      Returns:
      RGB
    • hsvToRgb

      public static void hsvToRgb​(double h, double s, double v, double[] rgb)
      Convert HSV color into RGB color
      Parameters:
      h - Hue [0,2*PI]
      s - Saturation [0,1]
      v - Value
      rgb - (Output) RGB value
    • hsvToRgb

      public static void hsvToRgb​(float h, float s, float v, float[] rgb)
      Convert HSV color into RGB color
      Parameters:
      h - Hue [0,2*PI]
      s - Saturation [0,1]
      v - Value
      rgb - (Output) RGB value
    • rgbToHsv

      public static void rgbToHsv​(double r, double g, double b, double[] hsv)
      Convert RGB color into HSV color
      Parameters:
      r - red
      g - green
      b - blue
      hsv - (Output) HSV value.
    • rgbToHsv

      public static void rgbToHsv​(float r, float g, float b, float[] hsv)
      Convert RGB color into HSV color
      Parameters:
      r - red
      g - green
      b - blue
      hsv - (Output) HSV value.
    • hsvToRgb

      public static <T extends ImageGray<T>> void hsvToRgb​(Planar<T> hsv, Planar<T> rgb)
      Converts an image from HSV into RGB.
      Parameters:
      hsv - (Input) Image in HSV format
      rgb - (Output) Image in RGB format
    • rgbToHsv

      public static <T extends ImageGray<T>> void rgbToHsv​(Planar<T> rgb, Planar<T> hsv)
      Converts an image from RGB into HSV. Pixels must have a value within the range of [0,1].
      Parameters:
      rgb - (Input) Image in RGB format
      hsv - (Output) Image in HSV format