difference between two colors

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

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C0EF4C.34D80860
	charset="iso-8859-2"

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_0015_01C0EF4C.34D80860
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 content=3D"text/html; charset=3Diso-8859-2" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#d8d0c8>
<DIV><FONT face=3DArial size=3D2>Can anyone think of any better function =
to get=20
difference between two colors.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-- Returns the difference between two =
colors.<BR>--=20
It should return the biggest difference when colors are WHITE and =
BLACK.<BR>--=20
Examples (all assume that 'color_importance' is 1):<BR>-- If colors are =
black{0,=20
0, 0} and white {255, 255, 255} it returns:<BR>--&nbsp;&nbsp;&nbsp; 0 + =
0 + 0 +=20
brightness_importance * 255 * 3 =3D brightness_importance * 765.<BR>-- =
If colors=20
are red {255, 0, 0} and green {0, 255, 0} it returns:<BR>--&nbsp;&nbsp; =
255 +=20
255 + 0 + brightness_importance * 0 =3D 255 + 255 =3D 510.<BR>-- If =
colors are gray=20
{127, 127, 127} and black {0, 0, 0} it returns:<BR>--&nbsp;&nbsp; 0 + 0 =
+ 0 +=20
brightness_importance * 127 * 3<BR>--&nbsp;&nbsp;&nbsp; =3D =
brightness_importance=20
* 381.<BR>-- (These examples don't assume that 'color_importance' is =
1):<BR>--=20
If colors are {127, 127, 127} and {127, 128, 127} it returns:<BR>--=20
color_importance * (1 + 0 + 1) + brightness_importance * 1 =3D<BR>-- =3D =
2 *=20
color_importance + brightness_importance.<BR>-- So: the difference =
between two=20
colors which have only one of the three color values<BR>-- different for =
only=20
one unit is 1, if '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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; -- The bigger this =
number is the=20
more important the brightness difference<BR>&nbsp;&nbsp;&nbsp; -- =
between the=20
two colors is.<BR>&nbsp;&nbsp;&nbsp; atom=20
brightness_importance<BR>&nbsp;&nbsp;&nbsp; -- Color importance. Modify =
these=20
two values if neccessary in the future.&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp; atom=20
color_importance</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; atom=20
ret</FONT><BR>&nbsp;&nbsp;&nbsp; integer red1, green1, blue1, red2, =
green2,=20
blue2</FONT></DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; color_importance =3D =

0.25<BR>&nbsp;&nbsp;&nbsp; brightness_importance =3D =
0.5<BR>&nbsp;&nbsp;&nbsp;=20
red1 =3D GetRValue (color1)<BR>&nbsp;&nbsp;&nbsp; green1 =3D GetGValue=20
(color1)<BR>&nbsp;&nbsp;&nbsp; blue1 =3D GetBValue =
(color1)<BR>&nbsp;&nbsp;&nbsp;=20
red2 =3D GetRValue (color2)<BR>&nbsp;&nbsp;&nbsp; green2 =3D GetGValue=20
(color2)<BR>&nbsp;&nbsp;&nbsp; blue2 =3D GetBValue =
(color2)<BR>&nbsp;&nbsp;&nbsp;=20
ret =3D =
(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
color_importance *=20
(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
-- red -=20
green<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
abs (abs (red1 - green1) - abs (red2 -=20
green2))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
-- red -=20
blue<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
+ abs (abs (red1 - blue1) - abs (red2 -=20
blue2))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
-- green -=20
blue<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
+ abs (abs (green1 - blue1) - abs (green2 -=20
blue2))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
--=20
brightness=20
difference<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
+ brightness_importance * abs ((red1 + green1 + blue1) - (red2 + green2 =
+=20
blue2))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
)<BR>&nbsp;&nbsp;&nbsp;=20

------=_NextPart_000_0015_01C0EF4C.34D80860--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu