Re: difference between two colors
- Posted by stabmaster_ at HOTMAIL.COM Jun 07, 2001
- 348 views
<html><DIV></DIV>>Can anyone think of any better function to get difference between two colors. <DIV></DIV>> <DIV> </DIV> <DIV>I use something like this:</DIV> <DIV> </DIV> <DIV> </DIV> <DIV>-- return values are 0 - 512k (approx)</DIV> <DIV>-- just do "? weighted_match({0,0,0}, {255,255,255})" to find out the maximum distance</DIV> <DIV>--</DIV> <DIV>function weighted_distance(sequence rgb1, sequence rgb2)</DIV> <DIV> integer rmean<BR> integer dr,dg,db</DIV> <DIV> </DIV> <DIV> rmean = floor((rgb1[1] + rgb2[1]) / 2)<BR> dr = (rgb1[1] - rgb2[1])<BR> dr *= dr<BR> dr = floor((dr * (512 + rmean)) / 256)</DIV> <DIV> </DIV> <DIV> dg = (rgb1[2] - rgb2[2])<BR> dg = (dg * dg) * 4</DIV> <DIV> </DIV> <DIV> db = (rgb1[3] - rgb2[3])<BR> db *= db<BR> db = floor((db * (767 - rmean)) / 256)</DIV> <DIV> </DIV> <DIV> return (dr + dg + db)</DIV> <DIV>end function</DIV>