Re: difference between two colors
- Posted by rforno at tutopia.com Jun 08, 2001
- 364 views
This is a multi-part message in MIME format. ------=_NextPart_000_0034_01C0EFA1.8BE3A920 charset="iso-8859-2" I'd assume r, g, b are the axis of a 3-dimensional space, and so their = possible values span a cube. Then I would compute the geometrical = distance between the 2 points in such a space, but I am too lazy to = write the function... ----- Original Message -----=20 From: Tone Skoda=20 To: EUforum=20 Sent: Thursday, June 07, 2001 7:20 AM Subject: difference between two colors Can anyone think of any better function to get difference between two = colors. -- Returns the difference between two colors. -- It should return the biggest difference when colors are WHITE and = BLACK. -- Examples (all assume that 'color_importance' is 1): -- If colors are black{0, 0, 0} and white {255, 255, 255} it returns: -- 0 + 0 + 0 + brightness_importance * 255 * 3 =3D = brightness_importance * 765. -- If colors are red {255, 0, 0} and green {0, 255, 0} it returns: -- 255 + 255 + 0 + brightness_importance * 0 =3D 255 + 255 =3D 510. -- If colors are gray {127, 127, 127} and black {0, 0, 0} it returns: -- 0 + 0 + 0 + brightness_importance * 127 * 3 -- =3D brightness_importance * 381. -- (These examples don't assume that 'color_importance' is 1): -- If colors are {127, 127, 127} and {127, 128, 127} it returns: -- color_importance * (1 + 0 + 1) + brightness_importance * 1 =3D -- =3D 2 * color_importance + brightness_importance. -- So: the difference between two colors which have only one of the = three color values -- different for only one unit is 1, if 'brightness_importance' is 0.5 = and -- 'color_importance' is 0.25. function reco_color_difference (atom color1, atom color2) -- The bigger this number is the more important the brightness = difference -- between the two colors is. atom brightness_importance -- Color importance. Modify these two values if neccessary in the = future. =20 atom color_importance atom ret integer red1, green1, blue1, red2, green2, blue2 color_importance =3D 0.25 brightness_importance =3D 0.5 red1 =3D GetRValue (color1) green1 =3D GetGValue (color1) blue1 =3D GetBValue (color1) red2 =3D GetRValue (color2) green2 =3D GetGValue (color2) blue2 =3D GetBValue (color2) ret =3D ( color_importance * ( -- red - green abs (abs (red1 - green1) - abs (red2 - green2)) -- red - blue + abs (abs (red1 - blue1) - abs (red2 - blue2)) -- green - blue + abs (abs (green1 - blue1) - abs (green2 - blue2)) ) -- brightness difference + brightness_importance * abs ((red1 + green1 + blue1) - = (red2 + green2 + blue2)) ) return ret end function ------=_NextPart_000_0034_01C0EFA1.8BE3A920 Content-Type: text/html; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-2"> <META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#d8d0c8> <DIV><FONT face=3DArial size=3D2>I'd assume r, g, b are the axis of a = 3-dimensional=20 space, and so their possible values span a cube. Then I would compute = the=20 geometrical distance between the 2 points in such a space, but I am too = lazy to=20 write the function...</FONT></DIV> <BLOCKQUOTE dir=3Dltr=20 style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A title=3Dtone.skoda at siol.net = href=3D"mailto:tone.skoda at siol.net">Tone Skoda</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = title=3DEUforum at topica.com=20 href=3D"mailto:EUforum at topica.com">EUforum</A> </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Thursday, June 07, 2001 = 7:20=20 AM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> difference between two = colors</DIV> <A = colors.<BR>-- It should return the biggest difference when colors are = WHITE=20 and BLACK.<BR>-- Examples (all assume that 'color_importance' is = 1):<BR>-- If=20 colors are black{0, 0, 0} and white {255, 255, 255} it=20 returns:<BR>-- 0 + 0 + 0 + brightness_importance * = 255 * 3 =3D=20 brightness_importance * 765.<BR>-- If colors are red {255, 0, 0} and = green {0,=20 255, 0} it returns:<BR>-- 255 + 255 + 0 + = brightness_importance *=20 0 =3D 255 + 255 =3D 510.<BR>-- If colors are gray {127, 127, 127} and = black {0, 0,=20 0} it returns:<BR>-- 0 + 0 + 0 + brightness_importance * = 127 *=20 3<BR>-- =3D brightness_importance * 381.<BR>-- = (These examples=20 don't assume that 'color_importance' is 1):<BR>-- If colors are {127, = 127,=20 127} and {127, 128, 127} it returns:<BR>-- color_importance * (1 + 0 + = 1) +=20 brightness_importance * 1 =3D<BR>-- =3D 2 * color_importance +=20 brightness_importance.<BR>-- So: the difference between two colors = which have=20 only one of the three color values<BR>-- different for only one unit = is 1, if=20 'brightness_importance' is 0.5 and<BR>-- 'color_importance' is=20 0.25.</FONT></DIV> <DIV><FONT face=3DArial size=3D2><BR>function reco_color_difference = (atom color1,=20 atom color2)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> -- The bigger this = number is=20 the more important the brightness difference<BR> -- = between=20 the two colors is.<BR> atom=20 brightness_importance<BR> -- Color importance. = Modify these=20 two values if neccessary in the future. = <BR> =20 atom color_importance</FONT></DIV> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2> atom=20 ret</FONT><BR> integer red1, green1, blue1, red2, = green2,=20 blue2</FONT></DIV></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> color_importance = =3D=20 0.25<BR> brightness_importance =3D = 0.5<BR> =20 red1 =3D GetRValue (color1)<BR> green1 =3D GetGValue = (color1)<BR> blue1 =3D GetBValue=20 (color1)<BR> red2 =3D GetRValue = (color2)<BR> =20 green2 =3D GetGValue (color2)<BR> blue2 =3D = GetBValue=20 (color2)<BR> ret =3D=20 = (<BR> =20 color_importance *=20 = (<BR> &n= bsp; =20 -- red -=20 = green<BR> &nbs= p; =20 abs (abs (red1 - green1) - abs (red2 -=20 = green2))<BR> &= nbsp; =20 -- red -=20 = blue<BR>  = ; =20 + abs (abs (red1 - blue1) - abs (red2 -=20 = blue2))<BR> &n= bsp; =20 -- green -=20 = blue<BR>  = ; =20 + abs (abs (green1 - blue1) - abs (green2 -=20 = blue2))<BR> &n= bsp;=20 = )<BR> = --=20 brightness=20 = difference<BR>  = ; =20 + brightness_importance * abs ((red1 + green1 + blue1) - (red2 + = green2 +=20 blue2))<BR> = )<BR> =20 return ret<BR>end = function</FONT></DIV><PRE>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D Get a FREE Golf Hat, a chance to win tickets to the 2002 U.S. Open and more golfing goodies! Just click below to find out how to take advantage of this offer from the USGA. <A = Or send an email To: EUforum-unsubscribe at topica.com This email was sent to: rforno at tutopia.com <A = ------=_NextPart_000_0034_01C0EFA1.8BE3A920--