Re: difference between two colors

new topic     » goto parent     » topic index » view thread      » older message » newer message

<html><DIV></DIV>&gt;Can anyone think of any better function to get difference
between two colors.
<DIV></DIV>&gt; 
<DIV>&nbsp;</DIV>
<DIV>I use something like this:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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>&nbsp; integer rmean<BR>&nbsp; integer dr,dg,db</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; rmean = floor((rgb1[1] + rgb2[1])&nbsp;/ 2)<BR>&nbsp; dr = (rgb1[1]
- rgb2[1])<BR>&nbsp; dr *= dr<BR>&nbsp; dr = floor((dr * (512 + rmean))&nbsp;/
256)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; dg = (rgb1[2] - rgb2[2])<BR>&nbsp; dg = (dg * dg)&nbsp; * 4</DIV>
<DIV>&nbsp; </DIV>
<DIV>&nbsp; db = (rgb1[3] - rgb2[3])<BR>&nbsp; db *= db<BR>&nbsp; db = floor((db
* (767 - rmean))&nbsp;/ 256)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; return (dr + dg + db)</DIV>
<DIV>end function</DIV>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu