Re: shape recognition by Peter
Peter
Tue Oct 14 04:36:47 CDT 2008
"Eduardo" <mm@mm.com> wrote in message news:gd0fc9$9d2$3@aioe.org...
> "Peter T" <peter_t@discussions> escribió en el mensaje
> news:umkBeDSLJHA.6000@TK2MSFTNGP04.phx.gbl...
>>> Analyze the image in this way:
>>> Start at the middle of each edge, and see the color of the pixels, each
>>> one going towards the center.
>>> Then go one pixel each time to one of the vertex and see if the same
>>> pattern repeats, but more inward than when i looked in the middle.
>>>
>>> I'm also thinking of making a function "ColorIsSimilar", because the
>>> color may be not exactly the same, but similar.
>>
>> When you say "similar" do you mean in terms of numerical RGB or
>> "visually".
>
> Good point.
> And of course, as they are images, they are for the human eye.
>
>> Point being, the eye does not perceive much separation with some colours,
>> eg greens, but very small differences in say cyan are very noticeable.
>>
>> If by similar you mean "visually" it might be worth looking into the 3D
>> "colour shape" or "colour space" (search w/out the "u"). There are
>> numerous algorithms out there of varying complexity to define a colour
>> shape. Having defined your space, fix your RGB's at points in the 3D
>> space, return their xyz coordinates form some arbitrary origin.
>>
>> The colour difference is the distance between the colours in the 3D
>> space.
>
> Well, the images can have a shadow, but they are just 2D (i think, though,
> i don't know when an image pass from 2D to be considered as 3D).
>
>>
>> If you are only looking for extremely small differences, eg up to about 5
>> in each RGB 0-255 scale (within range of say typical jpg representation
>> of same colour), it's probably OK to ignore the above for your purposes
>> and concentrate on what you are already doing.
>
> I'm looking for much bigger differences. For the kind of differences that
> the eye perceive as the outline of a shape (in a small bitmap).
>
> You made a good point here about the difference of sensitivity of the eye
> to different colors. I ignored that until now. I'll see what I'll do.
> I think for the time being i'll keep ignoring that, and when i have the
> recognition algorithm done, then i'll tweak the ColorsAreSimilar function.
>
> Thanks.
>
I think you have completely misunderstood what I meant by "3D colour shape",
it does not refer to your 2d image! It's merely one way to visualise and
compare individual colours.
This is probably not the right place to go into detail about colour, so just
a few things for you to look up elsewhere. There are many ways to define a
colour and most are definitions are multidimensional.
Here is just one way. First read up on the terms Hue, Saturation and
Luminance (HSL), colour-tone, colour intensity (mixture of pure colour with
grey of similar lightness) and luminosity (between absolute dark or black
and maximum brightness or white). An RGB colour can be redefined as HSL and
I assume functions have been posted in this group to convert RGB to HSL.
Now imagine two cones joined together, a bit like a spinning top. This is
our 3D colour shape. The vertical line between the points is the scale of
luminance. Any point on the circular faces where the cones join is 50% Lum,
the points are zero & 100% Lum respectively.
Take any horizontal circle through the double cone. Degrees around it
represent Hue. Rather than scaled at 0-360, Hue is normally measured as a
decimal 0-1 or a %. However I find it easiest to imagine a scale of 0-60
minutes of a clock. This places R, G & B at 0, 20 & 40 min, with yellow
(RG), cyan (GB) & magenta (BR) at 10, 30 & 50 minutes.
Saturation (grey to pure colour) is between zero on the vertical line
between the points, to 100% on the outer circumference.
So, convert your two RGB colours to HSL and place in the double cone, ie the
3d colour space. With a bit of geometry work out the xyz coordinates from an
arbitrary origin, eg the cone point that represents black. The colour
difference is the distance between the colours in the 3d space (square root
of the sum of the squares).
Unfortunately the human eye does not distinguish colour linearly in two
significant respects, our double cone 3d shape has limited use. The first is
the way eye separates colours, eg green wide banded vs cyan narrow banded
There is no one simple formula. The second is luminosity or lightness which
Olaf touched on. Green appears much brighter than blue of similar intensity.
This aspect is easy to compensate for with simple weighting, eg
LumA = 0.299 x Red + 0.587 x Green + 0.114 x Blue
ref. Rec 601 CIE
Notice how much more weight is given to green than blue.
As I mentioned previously there are plenty of 3d colour space definitions
out there. They are all subjective, based on how people on average perceive
colours, with greater or lesser complexity/simplification, depending on
needs.
End of colour intro !
I have no idea if you actually need to look further into the above, I guess
it really depends on what colours you have and how you need to differentiate
them.
You original question is interesting, in effect, pattern recognition. This
is probably bread and butter stuff to the "AI" guys, it might be worth
asking in one of their groups for a general approach (if you do - post a
link back here). Perhaps though as this task is relatively simple a brute
force approach is all that's required.
It's a shame you rubbed Olaf up the wrong way. You might consider re-reading
his suggestions and revising your comments, but that's up to you.
Regards,
Peter T