Into

Modules

Documentation

classPiiColorConverter

#include <PiiColorConverter.h>

Convert color spaces.

Inherits PiiDefaultOperation

Description

This operation performs color conversions between RGB, HSV, Y'CbCr, XYZ, CIELAB and other color spaces.

Inputs

imagea color image.

Outputs

imagea color image. The type of the output is that of the input, if possible. See ColorConversion for detailed information of type changes.

Classes

struct
struct

Properties

The type of color conversion.

A 3-by-3 conversion matrix (PiiMatrix<float> or PiiMatrix<double>) for the generic conversion.

double

Correction factor for gamma correction.

The XYZ coordinates of the white point of imaging equipment in prevailing illumination.

Public types

enum
{ GenericConversion, RgbToGrayMean, RgbToGrayMeanFloat, RgbToGraySum, RgbToHsv, HsvToRgb, BgrToRgb, XyzToLab, LabToXyz, RgbToLab, RgbToOhtaKanade, RgbToYpbpr, YpbprToRgb, RgbToYcbcr, YcbcrToRgb, RgbToY719, GammaCorrection }

Supported color conversion schemes.

Constructors and destructor

Public member functions

virtual void
(
  • bool reset
)

Checks the operation for execution.

double
( )
void
void
( )
void
(
  • double gamma
)
void
( )

Protected member functions

virtual void

Executes one round of processing.

Property details

  • ColorConversion colorConversion

    [read, write]

    The type of color conversion.

    The default value is GenericConversion.

  • PiiVariant conversionMatrix

    [read, write]

    A 3-by-3 conversion matrix (PiiMatrix<float> or PiiMatrix<double>) for the generic conversion.

    Let us assume the color to be converted is represented by . The converted color is obtained by , where A is the conversion matrix. The default value is a 3-by-3 identity matrix.

  • double gamma

    [read, write]

    Correction factor for gamma correction.

    Default is 1/2.2, which inverts the typical gamma of a monitor.

  • PiiVariant whitePoint

    [read, write]

    The XYZ coordinates of the white point of imaging equipment in prevailing illumination.

    This information is needed for the XYZ to LAB conversion. The white point is represented as a 1-by-3 matrix (PiiMatrix<float> or PiiMatrix<double>) that stores the X, Y, and Z coordinates, in this order. The default value is [95.05 100 108.88], which is the white point of a camera with ITU-R BT.709 primaries for a scene illuminated with a standard D65 light source. Since cameras never have ITU-R BT.709 primaries and the illumination is not likely to be D65, you had better find the real white point yourself.

Enumeration details

  • enum ColorConversion

    Supported color conversion schemes.

    • GenericConversion - convert the colors by multiplying the three-component color vector on each pixel with a generic conversion matrix. The result type will always be PiiMatrix<PiiColor<float> >.

    • RgbToGrayMean - calculate the mean of three color channels. Retains the type of color channels, but outputs a gray-level image.

    • RgbToGrayMeanFloat - calculate the mean of three color channels. The type of the output will be PiiMatrix<float>.

    • RgbToGraySum - calculate the sum of three color channels. The type of the output will be PiiMatrix<int> for all types except PiiMatrix<PiiColor<float> >, for which it equals the input.

    • RgbToHsv - convert RGB to HSV. Retains the input type. See PiiColors::rgbToHsv().

    • HsvToRgb - convert HSV to RGB. Retains the input type. See PiiColors::hsvToRgb().

    • BgrToRgb - reverse the order of color channels. Retains the input type.

    • XyzToLab - convert (linear) CIE XYZ colors to (non-linear, perceptually uniform) CIE L*a*b*. This conversion requires knowledge of the white point of imaging equipment. See whitePoint. The input must be (or it will converted to) a PiiMatrix<PiiColor<float> >, and so will be the output. Please note that there is no universal conversion from RGB to XYZ or from XYZ to L*a*b*. You need to know the primaries of your camera and the white point to make the conversion really work. See PiiColors::xyzToLab().

    • LabToXyz - the inverse of XyzToLab. Same restrictions apply. See PiiColors::labToXyz().

    • RgbToLab - convert RGB colors to CIE L*a*b*. This conversion requires knowledge of the primaries of the imaging equipment and its white point in prevailing illumination. This conversion works like GenericConversionFloat followed by XyzToLab. And no, there is no standard way to convert RGB to XYZ. Make sure your conversion matrix is correct.

    • RgbToOhtaKanade - perform a linear conversion from RGB to the maximally independent color components found by Ohta and Kanade back in 1980. Retains the input type.

    • RgbToY719 - convert non-linear RGB to luminance as defined in CIE Rec. 709. The type of the output will be PiiMatrix<float>. See PiiColors::rgbToY719().

    • RgbToYpbpr - convert non-linear RGB to Y'PbPr. Retains input type. Note that the color type must be able to store negative values. The preferable color channel type for this conversion is float. See PiiColors::rgbToYpbpr().

    • YpbprToRgb - convert Y'PbPr to non-linear RGB. Retains input type. See PiiColors::ypbprToRgb().

    • RgbToYcbcr - convert non-linear RGB to Y'CbCr. Retains input type. See PiiColors::rgbToYcbcr().

    • YcbcrToRgb - convert Y'CbCr to non-linear RGB. Retains input type. See PiiColors::ycbcrToRgb().

    • GammaCorrection - apply gamma correction to each color channel. Uses gamma as the correction factor. Retains input type. See PiiColors::correctGamma().

Function details

  • PiiColorConverter

    ()
  • virtual void check

    (
    • bool reset
    )
    [virtual]

    Checks the operation for execution.

    This function creates a suitable flow controller by calling createFlowController(). It then sets the flow controller to the active processor and sets the processor as the input controller for all inputs.

    If you change socket groupings in your overridden implementation, please call PiiDefaultOperation::check() after that. Otherwise, your new groupings will not be in effect.

    Reimplemented from PiiDefaultOperation.

  • ColorConversion colorConversion

    ()
  • PiiVariant conversionMatrix

    ()
  • double gamma

    ()
  • void setColorConversion

    ( )
  • void setConversionMatrix

    ( )
  • void setGamma

    (
    • double gamma
    )
  • void setWhitePoint

    ( )
  • PiiVariant whitePoint

    ()
  • virtual void process

    ()
    [protected, virtual]

    Executes one round of processing.

    This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.

    Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().

    Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns Running.

    Exceptions
    PiiExecutionException

    whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.

    Reimplemented from PiiDefaultOperation.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.