2

i want to compare to components with their filled colors if they are equal or not i do the following algorithm , i do averaging for the rgb as following

                double avg1 =(comp[0].Red+comp[0].Blue+comp[0].Green)/3;
                double avg2 =(comp[1].Red+comp[1].Blue+comp[1].Green)/3;

then compare them as following

                      double ratio  = avg1/avg2 ;
                      if(ratio > 0.8 && ratio < 1.2){} //then they are supposed to be equal

but this way isn't accurate at all

after searching i found that the best way is converting the image to HSL space and compare but i can't get how i compare 2 colors ?!! here

in other words after converting the image into HSL space what can i do ?!

help please !!

modification to the question for more clarification i mean with component (sequence of points) so in the averaging step actually i revisit all the points calculating the sum of the average of rgb for each pixel , then do averaging over the total number of the points

Community
  • 1
  • 1
user690069
  • 330
  • 4
  • 13

2 Answers2

1

Convert to HSL and use the difference in H (hue) to group colors.

Jacob
  • 34,255
  • 14
  • 110
  • 165
1

So if your question is "after converting the image into HSL space what can i do ?!" then here goes:

  1. convert the RGB image you've loaded to HSL using cvCvtColor() with the CV_RGB2HLS flag (the HSL image should be 3-channel, naturally)
  2. make three single-channel images (of same size) for the H, L, S channels to be separated into
  3. cvSplit( hls, h, l, s, 0 ) to separate the HSL image into channels
  4. Now the h_image will be just like any single-channel grayscale image. So after extracting components (do this from thresholding the RGB image, sometimes Hue channel image looks weird :P) simply compare the colors in the hue image that correspond to their co-ordinates.

Hope this helps.

AruniRC
  • 5,070
  • 7
  • 43
  • 73