Color Correction
Color Correction
Namespace
Emgu.CV
References
EMGU Reference
OpenCV Reference
Downloads
Example
The following example shows the use of different image
colour depths. The function of different colour depths allow the correction of image data though adjusting parameters.
Pre-Requisites
The code provided should run straight out of the Emgu.Example folder (V2.4.2), extract it to this location. If the code fails to execute re-reference the EMGU libraries and include the required opencv dlls in the bin directory. Note that the project is set to build to the output path "..\..\..\bin\" you may wish to change this if you don't extract to the EMGU.Example folder.
EMGU Coding Level: While the coding is not advanced the rated level for this example is Beginer/Intermediate. There is a lot of code within the example that can be intimidating to new comers but it's use is simple.
The Code
The code provided in this sample is basic there is little or no error checking. Support is available through the Forums but please try and examine the code before saying it doesn't work for you. The code is not optimised instead is better formatted to provided an understanding of the stages involved.
The programs operation is fairly simple, when a tab is selected the original image or current image being worked on is converted to the appropriate colour type using the Convert<>()
method call. Image correction or adjustment is simply applied by adding a constant supplied from the track-bar values to the appropriate depth of the image array. For example the image type BGR has 3 arrays of image data, the Blue, Green, and Red respectively. To adjust the blue colour intensity the values in the 0th array are adjusted, for Green the 1st, and Red the 3rd. The same method is applied to all colour type available.
By default changes in one colour space are not passed through to others, this allows you to evaluate how changes effect the image in different ways. To enable changes to be passed select the check-box in the lower right pane marked "Pass Changes Between Types".
The Code: Variables
Each image type is given it's own variable in which the contents of the image is copied to. From these variable individual image adjustment is allowed.
Image<Bgr, Byte> Image_BGR;
Image<Bgra, Byte> Image_BGRA;
Image<Gray, Byte> Image_GRAY;
Image<Hls, Byte> Image_HLS;
Image<Hsv, Byte> Image_HSV;
Image<Lab, Byte> Image_LAB;
Image<Luv, Byte> Image_LUV;
Image<Xyz, Byte> Image_XYZ;
Image<Ycc, Byte> Image_YCC;
To track which image type is in use, so that the program operates correctly when saving the image or copying it between colour depths, a public enum is employed. This is stored in the variable Depth as is changed to the correct image depth whenever a different tab is selected.
Imagetype Depth = Imagetype.Bgr; //stores the image depth
public enum Imagetype
{
Bgr, //Blue, green, red http://en.wikipedia.org/wiki/RGB
Bgra, //blue, green, red, alpha http://en.wikipedia.org/wiki/RGBA_color_space
Gray, //grayscale http://en.wikipedia.org/wiki/Grayscale
Hls, //aka HSL Hue, lightness, saturation http://en.wikipedia.org/wiki/HSL_and_HSV
Hsv, // Hue, saturation, Value http://en.wikipedia.org/wiki/HSL_and_HSV
Lab, //Lightness, a and b color-opponent dimensions http://en.wikipedia.org/wiki/Lab_color_space
Luv, //Lightness, u and v chromaticity coordinates, http://en.wikipedia.org/wiki/CIELUV
Rgb, //Red, green, blue http://en.wikipedia.org/wiki/RGB
Rgba, //Red, green, blue, aplha http://en.wikipedia.org/wiki/RGBA_color_space
Xyz, //http://en.wikipedia.org/wiki/CIE_1931_color_space
Ycc //aka YCbCr, Luma, chroma component Blue-Difference, chroma component Red-Difference http://en.wikipedia.org/wiki/YCbCr
};
The Code: Methods
What a method
does...
Method
Methods Available
Used
- name()
Unused
- name()
Bugs
- Numbered list If any