# Computer vision -- quantifying "similarity" of colors

Hi, I'm experimenting a little with computer vision, image analysis, feature detection, etc.  This question is fairly involved and I've done all the googling/web research I can do, and it probably requires someone with at least little experience in this area -- maybe I'll get lucky (wish I could offer more than 500 points).

I'm trying to analyze a photo and pick out the shapes/objects within the photo.  I've mixed and matched with the standard algorithms that are typically used for this (sobol, canny, others), and now I'm stepping back and crunching some basic numbers and just trying to apply some common sense.

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.  Like I said, I have already tried googling and web research, I probably need to hear from someone who has actually gone a little further down this road I'm *just* starting on.
ball.png
tabulated-RGB--HSL.png
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Too complex for me I'm afraid, but your comparing of colours did remind me of this which might be of interest:
0
Commented:
Here are some commonly used metrics: http://en.wikipedia.org/wiki/Color_difference
But it's actually much more complicated: http://people.virginia.edu/~smb3u/ColorVision2/ColorVision2.html
You may find this to be a practical approximation: http://en.wikipedia.org/wiki/Lab_color_space
0
Author Commented:
Yep, seen those links.  Played with most of the math it describes.  What do you mean a practical approximation?

To summarize, there must be a transform that groups my data in the desired fashion (orange vs beige vs white) regardless of brightness.  I thought it was hue or hue+saturation but apparently it is not.

And frankly the transform can't be much more complicated than hsv or hsi or hsl transforms because there's not that much input data.  There are some simple equations I could plug into the next excel cells that would make orange and dark orange numerically similar.

There are a million things I could try, could really benefit from some experience here.
0
Commented:
You might use L in L*a*b space, if you can calibrate your display device.
0
Author Commented:
Okay, I'll try that.
0
IT Business Systems Analyst / Software DeveloperCommented:
Can't you just do a threshold on the Saturation channel? Pick an appropriate threshold level, say 100 maybe and then any pixel with saturation over that is the ball.
0
Commented:
I was going to suggest what mccarl answered. The hue will change in the shade because it gets more colour from the diffuse light.

Another way to look at this problem is to consider the answer you want. You are looking for an orange ball in the image, rather than trying to decide where orange is. The typical method for doing this is to have a reference object, in this case that would be an orange circle. The matching process involves approximating the location of the ball by subtracting the reference object from the image. As long as the subtraction produces a result close enough to zero then you have a match. The shadow or a small object obstructing the view should not matter.

The trick is how do you locate the reference object in the first place. If you can find enough orange in the image (say a 8x8 square), you can start from there and fit the circle by expanding and centering. You could try testing in a circular pattern around the first guess. Another possibility, treat the image as 4x4 pixel tiles. Center the reference circle in each tile and score for matching. With that result, make an image where each pixel is the match score from a 4x4 tile. You know have a much smaller, monochrome image to test.
0
Author Commented:
@satsumo

"The hue will change in the shade because it gets more colour from the diffuse light."

Thanks, this is the exact thing I didn't know, I thought "hue" was a property of the ball.   If two pixels are from the same object but are shaded differently, is there some calculable color property that does *not* change?  (I haven't tried the L in L*a*b lab space yet, but it's something to try... however you sound like you know something about this, would you suggest something different or do you know that there is no such property that is unaffected by the shade?)

I can't subtract a known reference object because my actual problem is to find any object.  So all I'm trying to do at the moment as step 0 is to find regions of similar color that might represent an object in space.  And my immediate problem is simply that "similar" should disregard shading/shadows.
0
Commented:
Object recognition involves a lot more than quantifying "similarity" of colors.
One way to reduce the effect of differences in illumination is to suppress the low frequencies in the log domain
http://www.cs.sfu.ca/~stella/papers/blairthesis/main/node35.html
0
IT Business Systems Analyst / Software DeveloperCommented:
If two pixels are from the same object but are shaded differently, is there some calculable color property that does *not* change?
In a word no! The problem is, as you say, "shaded differently". The different shades are due to different proportions/amounts of the different types of light (direct, diffuse, etc) falling on the ball. Take this extreme example, if you had the same setup as in the image above, but you get a torch that can make a tight spot light and you put a blue filter on it. Now shine that on the top of the ball, what will happen? The top of the ball will look bluish orange where the spot light falls, but the bottom/shaded side will look orange exactly as it does in the above image because it gets none of that spot light.

Now the above image is not that extreme, but still the top of the ball is primarly lit by the direct light hitting it and is affected by its colour. Whereas, the bottom of the ball is lit by the light that has bounced off all the walls and the objects in the room and the colour of that light has been affected by all those objects, and so when it hits the ball it can/will be different colour to that of the direct light on the top.

I can't subtract a known reference object because my actual problem is to find any object
Is the problem, to also be able to find this "any object" against any background, or will it always be this same background? (ie. the camera is fixed and you just need to find objects that come into it's field of view)   If this is ok, you can go the other way and substract an image of the background with no object in it from the image above, which will leave most of the background pixel values around 0 and any pixels where the ball is should be significantly NON-zero. Just a thought?
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
"Object recognition involves a lot more than quantifying "similarity" of colors."

Obviously.
0
Author Commented:
Thanks mccarl, that helps a lot -- I understand (belatedly, perhaps) from what you're saying that the color of light bouncing off the ball and towards the camera is a function of both the ball and -- significantly -- the light source(s), so it is quite possible the shaded area appears quite different in these numbers available to me.  I won't waste time looking for a magic discriminator then, and fall back to fuzzier/tuned techniques.

Different backgrounds too, but otherwise that's a nice suggestion.  I'm biting off more than I can chew, but I like to do that sometimes.
0
IT Business Systems Analyst / Software DeveloperCommented:
Glad to help & good luck! :)
0
Commented:
Something you might try something like the PlayStation EyeToy does. It assumes the camera is not moving. So it can compare one image to the previous image, any difference is movement. In your case, the background may be different but it does not change between frames. As long as the target objects move enough to give you a reference you should be able to detect the difference.

However, identifying non-specific objects without a reference is a very difficult problem. The best solution I've seen for that was by Google. They used their image search data to match objects against. To locate a static object against static background is similarly tricky, because the program has no idea what the object is. This is why early computer vision research used things like colored balls.

Thanks for the points.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Algorithms

From novice to tech pro — start learning today.