EasyColor - Pre-Processing Color Images
EasyColor makes color image processing as efficient as possible by detecting, classifying and analyzing objects. Several conversion functions mean that any color system can be processed.
The human eye is sensitive to light:
- Intensity, or achromatic sensation, captured by grayscale images.
- Wavelength, or chromatic sensation, described in red, green and blue primary colors.
True color digital images (24 bits per pixel; 8 bits per RGB channel) represent as many colors as the eye can distinguish.
Visible color gamut in the XYZ color space
There are three color systems:
- Mixture systems (RGB/XYZ) give the proportions of the three primaries to be combined.
- YUV Luma/chroma systems (XYZ/YUV) separate the achromatic (Y) and chromatic sensations (U & V). Used when a black and white image is required as well (television).
- Intensity/saturation/hue systems (RGB/XYZ/YUV) separate achromatic (black and white Intensity) from enhanced chromatic (color Saturation and Hue) sensations. Used to eliminate lighting effects, or to convert RGB images to another color system. More saturated colors are more vivid, less saturated ones are grayer.
In general:
- RGB is used by monitors, cameras and other display devices.
- YUV is used for efficient transmission of color images by compressing the chrominance information.
- XYZ is used for device-independent color representation.
All image processing operations can use quantized coordinates: discrete values in the [0..255] interval, which use a byte representation to store images in a frame buffer.
Color system conversion operations can also use simpler unquantized coordinates: continuous values, often normalized to the [0..1] interval.
A color image is a vector field with three components per pixel. All three RGB components reflected by an object have amplitude proportional to the intensity of the light source. By considering the ratio of two color components, one obtains an illumination-independent image. With a clever combination of three pieces of information per pixel, one can extract better features.
There are 3 ways to process a color image:
- Component extraction: you can extract the most relevant feature from the triple color information, to reduce the amount of data. For instance, objects may be distinguished by their hue, a pre-processing step could transform the image to a gray-level image containing only hue values.
- De-coupled transformation: you can perform operations separately on each color component. For instance, adding two images together adds the red, green and blue components and stores the result, component by component, in a resulting color image.
- Coupled transformation: you can combine all three color components to produce three derived components. For example, converting YIQ to RGB.
Easycolor supports color systems RGB, XYZ, L*a*b*, L*u*v*, YUV, YIQ, LCH, ISH/LSH, VSH and YSH.
RGB is the preferred internal representation as it is compatible with 24-bit Windows Bitmaps.
|
RGB-based |
XYZ-based |
YUV-based |
---|---|---|---|
Mixture |
— |
||
Luma/Chroma |
— |
||
Intensity/Saturation/Hue |
EasyColors Lookup tables provide an array of values that define what output corresponds to a given input, so an image can be changed by a user-defined transformation.
A color pixel can take 16,777,216 (224) values, a full color LUT with these entries would occupy 50 MB of memory and transforms would be prohibitively time-consuming. Pre-computed LUTs make color transforms feasible.
To transform a color image, you initialize a color LUT using one of the following functions:
□ | LUT for Gain/Offset (Color) : EasyImage::GainOffset, |
□ | LUT for Color Calibration: EColorLookup::Calibrate, |
□ | LUT for Color Balance: EColorLookup::WhiteBalance, |
□ | EColorLookup::ConvertFromRGB, EColorLookup::ConvertToRGB. |
This color LUT is then used in a transform operation such as EasyColor::.Transform or you can create a custom transform using EColorLookup which takes unquantized values (continuous, normalized to [0..1] intervals), and specifies the source and destination color systems. Some operations use the LUT on-the-fly thus avoid storing the transformed image, for example to alter the U (of YUV) component while the image is in RGB format.
The optimum combination of accuracy and speed is determined by the choice of IndexBits and Interpolation - the accuracy of the transformed values roughly corresponds to the number of index bits.
- Fewer table entries mean smaller storage requirements, but less accuracy.
- No interpolation gives quicker running time, but less accuracy. Interpolation can recover 8 bits of accuracy per component. When the involved transform is linear (such as YUV to RGB), interpolation always gives exact results, regardless of the number of table entries.
Index Bits |
Number of entries |
Table size (bytes) |
---|---|---|
4 |
2(3*4) = 4,096 |
14,739 |
5 |
2(3*5) = 32,768 |
107,811 |
6 |
2(3*6) = 262,144 |
823,875 |
YUV images can be minimized without degrading visual quality using function Format444To422 to convert from 4:4:4 to 4:2:2 format (or you can convert Format 422 To 444).
- 4:4:4 uses 3 bytes of information per pixel.
- 4:2:2 uses 2 bytes of information per pixel.
It stores the even pixels of U and V chroma with the even and odd pixels of Y luma as follows:
Y[even] U[even] Y[odd] V[even]
A color image contains three color planes of continuous tone images.
A gray-level image can be a component of a color system.
EasyColor can change or extract one plane at a time, or all three together. See Compose, Decompose, GetComponent, SetComponent.
These operations can use a color LUT to transform on the fly, they could build an RGB image from lightness, saturation and hue planes.
EasyColor functions perform the necessary interleaving / un-interleaving operations to support Windows bitmap format of interleaved color planes (blue, green and red pixels follow each other).
The trick is to define a regular gamut of 256 colors and each color will be assigned to pixels with a corresponding gray-level value.
To define pseudo-color shades, you specify a trajectory in the color space of an arbitrary system. You can then pseudo-color using the drawing functions color palette (see Image and Vector Drawing) then save and/or transform it like any other color image.
Gray-level and pseudo-colored image
This EasyColor process takes a set of distinct colors and associates each pixel with the closest color, using a layer index that can then be used in EasyObject with the labeled image segmenter to improve blob creation.
Raw image and segmented image (3 colors)