This post once again concentrates on understanding “What is Color Space” and how can it be used for Different projects you do and how well can you use the basics to finish the same.I still see a lot of users asking questions about Color Spaces and how to use them and this post satisfies your Thirst…Look at this picture.

This picture (from Wikipedia) shows a man wearing a blue dress with a green background.Now lets split this image channels into the constituent channels and then see what are the constituents of the image with the help of this program.
/*Program to remove the components and show them apart..
.make the users realize the importance
of color space in OpenCV*/
/*All the includes*/
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
#include "conio.h"
int main() {
int i,j,k;
/*Load the image*/
IplImage* frame=cvLoadImage("Man Color Image.jpg",1);
cvNamedWindow("main", CV_WINDOW_AUTOSIZE);
cvNamedWindow("red", CV_WINDOW_AUTOSIZE);
cvNamedWindow("green", CV_WINDOW_AUTOSIZE);
cvNamedWindow("blue", CV_WINDOW_AUTOSIZE);
if(frame==NULL){ /*If image not found then exit.
This is the function of this loop */
printf("the file doesnot exist");
exit(0);
}/*creating 3 images all one channel*/
IplImage* blue=cvCreateImage( cvGetSize(frame), 8, 1 );
IplImage* green=cvCreateImage( cvGetSize(frame), 8, 1 );
IplImage* red=cvCreateImage( cvGetSize(frame), 8, 1 );
//-----------------------------------------
/*Setting the Image Channel of interest(COI)*/
cvSetImageCOI( frame, 1 );
/*Here CvCopy sees the COI and ROI and then copies the channels to be copied
Here we set the first channel as the channel of interest*/
cvCopy( frame, blue, NULL );/*Copy the first channel */
cvSetImageCOI( frame, 2 );/*Set the COI to second channel*/
cvCopy( frame, green, NULL );/*Copy the second channel*/
cvSetImageCOI( frame, 3 );/*Set the COI to third channel*/
cvCopy( frame, red, NULL );/*Copy the third channel*/
cvShowImage("main",frame);
cvShowImage("blue",blue);
cvShowImage("green",green);
cvShowImage("red",red);
cvSaveImage("main.jpg",frame);
cvSaveImage("blue.jpg",blue);
cvSaveImage("green.jpg",green);
cvSaveImage("red.jpg",red);
cvWaitKey();
cvDestroyWindow( "main" );
cvDestroyWindow( "red" );
cvDestroyWindow( "green" );
cvDestroyWindow( "blue" );
return 0;/*This statement is compiler specific and might change.
As i already said that I am using DEV C++ as my compiler*/
}

Blue Channel

Green Channel

Red Channel
Now why is the Dress in the Red Channel low in Intensity..? (Do not worry about the sizes of the Image I have changed them to suit the looks and spacing).Its because the Red color is less in the blue area “but it is not zero(for most of the pixels in real time imaging)”.
Just look at the upper left corner in the green Image behind the head of the man.Don’t you see the leaves of the tree clearly with more intensity.Its because the leaves are green and which means they have more green color and less of the other colors.Because they are green.A matter of Fact (the leaves are green because they do not absorb the green color they reflect the green color).
If you look in the blue channel, the background is very dark which means that there is less “blue” intensity….think for some points like this from the image.
So any area in an image no matter what color it is has RGB values .
Now 8*8*8=(2^8)*(2^8)*(2^8)=2^24 which roughly comes to 16 million colors.So its is very difficult to detect specific colors using RGB hence we do a color space conversion.I have already posted a topic describing the importance of the HSV color space.
Now if you observe the higher the ‘R’ ,’G', ‘B’ value higher is the intensity and when R=G=B=255 which means that its pure white light, which again means that the intensity is contained in a combination of the RGB values…similarly some more arithmetic done on the RGB gives the HUE nd the saturation values.
Now look at the upper left corner of the green image …? Dont you think its brighter.The plants are green Just look at the thick green leaves they are brighter.If a part in the image is brighter then it means that it has higher intensity and higher intensity means that the higher is the number.
Just try to satisfy yourself with what you think and what is present.Ponder over this post for sometime it would be a good time investment.
Remember->brighter Region signifies higher intensity which again means higher numbers
Darker regions means the vice versa…please give me some feedback about my explanation
I will try to Improve the same.
