quantifying "similarity" of colors
Hi, this isn't a question about opencv itself, but a question that I came across while using it and I am sure you are the correct audience for it.
I'm just starting out with computer vision, trying to analyze a photo and pick out the shapes/objects within the photo. I've mixed and matched with a couple of the standard algorithms that come with opencv, and now I'm stepping back and crunching some basic numbers and just trying to apply some common sense, getting a little more fundamental.
I took a photo of a ball on a table (attached) and tried to imagine an algorithm to find the ball. It is the big region of orange in the middle, but the first problem is that it is not perfectly uniform orange, it has a shadow across it so that it is brightest at the upper left and darker at the lower right. It's all the same color but varying brightness.
So I thought, how do I normalize on brightness so that the computer sees a blob of uniform orange in the middle? Well, if I take the RGB data and transform it to HSL, well then perhaps I should see the "luminance" (L) change across the ball and the H+S will stay the same. Then the computer could just modify all the colors to have the same "L" of the HSL and then we will see a relatively uniform orange.
So I sampled some pixels and did the RGB->HSL transform by hand (tabulated and color coded, also attached), and found that it does not work like that. I thought hue and saturation, or at LEAST the hue, would be uniform across the ball. It is not, the saturation and hue both drop significantly as the shadow increases.
Out of curiosity I sampled some points from the regions of the picture from the back wall (gray-ish) and the table it's sitting on (beige). I started to realize that I couldn't pick out anything numerically similar between the groups of colors (orange ball, gray wall, beige table). I would have thought that the hue, or hue+saturation stayed the same while maybe the luminance changes with the brightness.
So... if that is not the rule, what IS the rule? What is the math that would group these sets of points together? Maybe there is some other transform other than RGB-HSL that makes it apparent? Obviously there is something, since it is IMMEDIATELY obvious to our eyes: those are orange, those are gray, and those are beige (of varying brightnesses).
Thanks very much for reading this far, and any thoughts.
Perhaps you should use the LAB color space.
"I took a photo of a ball on a table (attached) and tried to imagine an algorithm to find the balll". How about training a classifier / or model which will figure out the algorithm for detection by itself. That's called deep learning. Let the neuronal network figure a way how to detect your ball.
@holger please pay attention of post date
Oohhh i see - this was 4 years ago. I will pay attention to this in the future. So this was a zombie post from me.