Click to See Complete Forum and Search --> : Colour Detection using HSV
edo_uk
January 16th, 2007, 12:18 PM
Hi, I have converted from RGB to HSV and wondered how you find the colour you are looking for in HSV. I used the euclidean distance with the RGB and can't figure out how to do it with HSV. Can anyone help?
Ben Edmonds
MikeAThon
January 16th, 2007, 01:36 PM
HLS might be easier. HLS is a cylindrical coordinate system, so color difference is easier to compute.
// compute color difference in HLS space (which are cylindrical coords)
// dc = s1^2 + s2^2 - 2*s1*s2*cos(h1-h2) + (L1-L2)^2
::ColorRGBToHLS( m_crTargetColor, &HH, &LL, &SS );
dH = HH - hue;
dL = LL - lum;
dS = SS*SS + sat*sat;
dclr = (int)((double)dS - 2.0*SS*sat*cos( TwoPiOver240*dH ) + (double)dL*dL);
Mike
PS added much later: HLS is not cylindrical (it's a bi-hexcone) and this equation is therefore wrong. See posts below.
edo_uk
January 18th, 2007, 03:06 PM
i don't know if i'm doing something wrong but i converted to the HSL using http://en.wikipedia.org/wiki/HSL_color_space.
And i assume that by the variable hue,sat and lum are the reference colour from this i am getting anwers like 8.5e+4 which i thought was quite odd. Can anyone help plz
Cheers
Ben
edo_uk
April 5th, 2007, 06:49 PM
Hi, i don't suppose anyone knows where i can get a reference to the formula provide by MikeAThon?
MikeAThon
April 5th, 2007, 07:09 PM
The formula was derived based on basic geometry, and the Euclidean distance between points, on the assumption that HLS is a cylindrical coordinate system.
But it seems that this asumption is wrong, and that HLS is actually a bi-conical (or bi-hexcone) coordinate system: http://msdn2.microsoft.com/en-us/library/ms536815.aspx
So, don't use the formula, or re-derive it based on the true nature of the HLS coordinate system.
Mike
edo_uk
April 6th, 2007, 08:13 AM
It may not work for the HLS colour model but the HSV model is a cylindrical model and it appears to work quite well for this
quickanswer
October 4th, 2007, 02:04 PM
Actually, neither of these is a cylindrical space. It is HSI which is cylindrical. HSV is a hexcone and HLS is a double hexcone. For a description of HSV and HLS see 3D Computer Graphics by Alan Watt, 2nd edition, chapter 14. For a description of HSI see Digital Image Processing by Kenneth R. Castleman, 1996, chapter 21.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.