1. difference between two colors

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 message » categorize

2. Re: difference between two colors

Tone Skoda wrote:

> Can anyone think of any better function
> to get difference between two colors.

The code in Dos32Lib does something similar to map the colors in a Euphoria
bitmap to the best fit in the current palette. It seemed to work just fine
with just comparing the difference of rgb. Essentially just a pared-down
version of what you're proposing:

   best = #FFFFFF
   index = 0
   -- examine each option
   for i = 1 to length options do
      -- get difference for each rgb
      for j = 1 to 3
         diff += abs( color[j] - option[i][j] )
      end for
      if diff < best then
         index = i
         best = diff
      end if
   end for

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: difference between two colors

<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 message » categorize

4. Re: difference between two colors

This is a multi-part message in MIME format.

------=_NextPart_000_0018_01C0F057.414A8E40
	charset="iso-8859-2"

Here are test results. Difference no.14 should be biggger than =
difference no.13, don't you think? My function did that.
I want function to be as similar as possible to the way that human eye =
sees it.


     see1 see2 color1 - color2 =3D weighted_distance =
Cuny_color_difference reco_color_difference=20
      1   255,255,255 - 0,0,0 =3D 584970 765 382=20
      2   255,0,0 - 0,255,255 =3D 584970 765 127=20
      3   255,0,0 - 0,255,0 =3D 422408 510 127=20
      4   255,0,0 - 255,255,255 =3D 390150 510 382=20
      5   0,50,0 - 200,255,200 =3D 367943 605 305=20
      6   255,0,0 - 0,0,255 =3D 324870 510 127=20
      7   255,0,0 - 0,150,0 =3D 252308 405 180=20
      8   255,0,0 - 0,100,0 =3D 202308 355 205=20
      9   0,255,0 - 0,255,255 =3D 194820 255 255=20
      10   255,0,0 - 0,50,0 =3D 172308 305 230=20
      11   50,50,100 - 200,200,200 =3D 171064 400 225=20
      12   0,0,255 - 255,0,255 =3D 162308 255 255=20
      13   0,255,0 - 255,255,0 =3D 162308 255 255=20
      14   127,127,127 - 255,255,255 =3D 147392 384 192=20
      15   127,127,127 - 0,0,0 =3D 145097 381 190=20
      16   100,100,100 - 200,200,200 =3D 89960 300 150=20
      17   127,127,127 - 255,200,100 =3D 67948 228 164=20
      18   255,0,0 - 100,0,0 =3D 64661 155 155=20
      19   255,0,0 - 150,0,0 =3D 30749 105 105=20
      20   255,0,0 - 200,50,0 =3D 18732 105 55=20
      21   255,0,0 - 200,0,0 =3D 8732 55 55=20
      22   127,127,127 - 127,128,127 =3D 4 1 1=20
      23   127,127,127 - 127,127,128 =3D 2 1 1=20
      24   255,0,0 - 255,0,0 =3D 0 0 0=20




Here is program which makes html table above:


-- color difference test.ex
-- test two-color-difference functions
-- 08. junij 2001 12:55, petek

include sort.e

constant output_file =3D "colordif.htm"

function abs (atom x)
 if x < 0 then return -x else return x end if
end function

global function RGB( integer r, integer g, integer b )
   =20
    -- return RGB value of triad
    return r + ( g * 256 ) + ( b * 256 * 256 )=20
   =20
end function

-- returns html color string
function rgb_to_html (sequence rgb)=20
 --// sequence ret
 --// ret =3D sprintf ("%x", RGB (rgb [1], rgb [2], rgb [3]))
 --// ret =3D repeat ('0', length ("000000") - length (ret)) & ret
 --// return ret

 sequence ret, t
 ret  =3D "#000000"
 t =3D sprintf ("%x", rgb [1])
 ret [2..3] =3D repeat ('0', 2 - length (t)) & t
 t =3D sprintf ("%x", rgb [2])
 ret [4..5] =3D repeat ('0', 2 - length (t)) & t
 t =3D sprintf ("%x", rgb [3])
 ret [6..7] =3D repeat ('0', 2 - length (t)) & t
 return ret
end function

-- function by  Mic
-- return values are 0 - 512k (approx)
-- just do "? weighted_match({0,0,0}, {255,255,255})" to find out the =
maximum distance
--
function weighted_distance(sequence rgb1, sequence rgb2)
  integer rmean
  integer dr,dg,db
=20
  rmean =3D floor((rgb1[1] + rgb2[1]) / 2)
  dr =3D (rgb1[1] - rgb2[1])
  dr *=3D dr
  dr =3D floor((dr * (512 + rmean)) / 256)
=20
  dg =3D (rgb1[2] - rgb2[2])
  dg =3D (dg * dg)  * 4
 =20
  db =3D (rgb1[3] - rgb2[3])
  db *=3D db
  db =3D floor((db * (767 - rmean)) / 256)
=20
  return (dr + dg + db)
end function

-- function by David Cuny
function Cuny_color_difference (sequence rgb1, sequence rgb2)
    atom diff
    diff =3D 0
    -- get difference for each rgb
    for j =3D 1 to 3 do
        diff +=3D abs( rgb1[j] - rgb2[j] )
    end for
    return diff
end function

-- 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 (sequence rgb1, sequence rgb2)
=20
    -- 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
=20
    color_importance =3D 0.25
    brightness_importance =3D 0.5
    red1 =3D rgb1 [1]
    green1 =3D rgb1 [2]
    blue1 =3D rgb1 [3]
    red2 =3D rgb2 [1]
    green2 =3D rgb2 [2]
    blue2 =3D rgb2 [3]
    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

function sort_result (sequence s1, sequence s2)
 if s1 [3] [1] > s2 [3] [1] then return -1
 elsif s1 [3] [1] =3D s2 [3] [1] then return 0
 else return 1 end if
end function

-- 'func_names' is sequence with all function names to test.
procedure test_functions (sequence func_names)
 atom diff
 sequence rgb1, rgb2
 sequence func_ids
 sequence colors=20
 integer fn
 -- 1. rgb1, 2. rgb2, 3. sequence {function differences, sorted by first =
one}
 sequence result=20
 colors =3D
 {
  {{255, 255, 255}, {0, 0, 0}},
  {{127, 127, 127}, {0, 0, 0}},
  {{127, 127, 127}, {255, 255, 255}},
  {{127, 127, 127}, {127, 128, 127}},
  {{127, 127, 127}, {127, 127, 128}},
  {{255, 0, 0}, {255, 0, 0}},
  {{255, 0, 0}, {0, 255, 0}},
  {{255, 0, 0}, {0, 0, 255}},
  {{255, 0, 0}, {0, 255, 255}},
  {{255, 0, 0}, {255, 255, 255}},
  {{0, 255, 0}, {0, 255, 255}},
  {{0, 0, 255}, {255, 0, 255}},
  {{0, 255, 0}, {255, 255, 0}},
  {{127, 127, 127}, {255, 200, 100}},
  {{100, 100, 100}, {200, 200, 200}},
  {{50, 50, 100}, {200, 200, 200}},
  {{0, 50, 0}, {200, 255, 200}},
  {{255, 0, 0}, {200, 0, 0}},
  {{255, 0, 0}, {150, 0, 0}},
  {{255, 0, 0}, {100, 0, 0}},
  {{255, 0, 0}, {200, 50, 0}},
  {{255, 0, 0}, {0, 50, 0}},
  {{255, 0, 0}, {0, 150, 0}},
  {{255, 0, 0}, {0, 100, 0}}
 }
 result =3D repeat (repeat (0, 3), length (colors))
 fn =3D open (output_file, "w")
 puts (fn, "<html><body>\n")
 func_ids =3D repeat (0, length (func_names))
 for i =3D 1 to length (func_names) do
         func_ids [i] =3D routine_id (func_names [i])
 end for=20

 for i =3D 1 to length (colors) do
  rgb1 =3D colors [i] [1]
  rgb2 =3D colors [i] [2]
  result [i] [1] =3D rgb1
  result [i] [2] =3D rgb2
  result [i] [3] =3D repeat (0, length (func_names))
  -- each function
  for j =3D 1 to length (func_ids) do
   diff =3D call_func (func_ids [j], {rgb1, rgb2})
   result [i] [3] [j] =3D diff
  end for
 end for

 result =3D custom_sort (routine_id ("sort_result"), result)

 -- print sorted results
 puts (fn, "<table border=3D1>\n")
 -- column headers=20
 puts (fn, "<tr>\n")
 puts (fn, "<td></td>\n")
 puts (fn, "<td>see1</td>\n")
 puts (fn, "<td>see2</td>\n")
 puts (fn, "<td>color1</td>\n")
 puts (fn, "<td>-</td>\n")
 puts (fn, "<td>color2</td>\n")
 puts (fn, "<td>=3D</td>\n")
 for i =3D 1 to length (func_names) do   =20
  if i =3D 1 then
   puts (fn, "<td><b>" & func_names [i] & "</b></td>\n")
  else
   puts (fn, "<td>" & func_names [i] & "</td>\n")
  end if
 end for
 puts (fn, "</tr>\n\n")
 printf (fn, "%s", {"\n\n"})

 for i =3D 1 to length (result) do
  rgb1 =3D result [i] [1]
  rgb2 =3D result [i] [2]

  puts (fn, "<tr>\n")
  printf (fn, "<td>%d</td>\n", i)
  puts (fn, "<td bgcolor=3D" & rgb_to_html (rgb1) & "></td>\n")
  puts (fn, "<td bgcolor=3D" & rgb_to_html (rgb2) & "></td>\n")
  printf (fn, "<td>%d,%d,%d</td>\n", {rgb1 [1], rgb1 [2], rgb1 [3]})
  puts (fn, "<td>-</td>\n")
  printf (fn, "<td>%d,%d,%d</td>\n", {rgb2 [1], rgb2 [2], rgb2 [3]})
  puts (fn, "<td>=3D</td>\n")
  for j =3D 1 to length (func_names) do
   printf (fn, "<td>%d</td>\n", floor (result [i] [3] [j]))
  end for
  puts (fn, "</tr>\n\n")
 end for

 puts (fn, "</table>")
 close (fn)
 puts (1, "Done! See file " & output_file & ".\n")
end procedure

test_functions ({"weighted_distance", "Cuny_color_difference", =
"reco_color_difference"})
=20

------=_NextPart_000_0018_01C0F057.414A8E40
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>Here are test results. Difference no.14 =
should be=20
biggger than difference no.13, don't you think? My function did=20
that.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I want&nbsp;function to be as similar =
as possible=20
to the way that human eye sees it.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<TABLE border=3D1>
  <TBODY>
  <TR>
    <TD></TD>
    <TD>see1</TD>
    <TD>see2</TD>
    <TD>color1</TD>
    <TD>-</TD>
    <TD>color2</TD>
    <TD>=3D</TD>
    <TD><B>weighted_distance</B></TD>
    <TD>Cuny_color_difference</TD>
    <TD>reco_color_difference</TD></TR>
  <TR>
    <TD>1</TD>
    <TD bgColor=3D#ffffff></TD>
    <TD bgColor=3D#000000></TD>
    <TD>255,255,255</TD>
    <TD>-</TD>
    <TD>0,0,0</TD>
    <TD>=3D</TD>
    <TD>584970</TD>
    <TD>765</TD>
    <TD>382</TD></TR>
  <TR>
    <TD>2</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#00ffff></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,255,255</TD>
    <TD>=3D</TD>
    <TD>584970</TD>
    <TD>765</TD>
    <TD>127</TD></TR>
  <TR>
    <TD>3</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#00ff00></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,255,0</TD>
    <TD>=3D</TD>
    <TD>422408</TD>
    <TD>510</TD>
    <TD>127</TD></TR>
  <TR>
    <TD>4</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#ffffff></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>255,255,255</TD>
    <TD>=3D</TD>
    <TD>390150</TD>
    <TD>510</TD>
    <TD>382</TD></TR>
  <TR>
    <TD>5</TD>
    <TD bgColor=3D#003200></TD>
    <TD bgColor=3D#c8ffc8></TD>
    <TD>0,50,0</TD>
    <TD>-</TD>
    <TD>200,255,200</TD>
    <TD>=3D</TD>
    <TD>367943</TD>
    <TD>605</TD>
    <TD>305</TD></TR>
  <TR>
    <TD>6</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#0000ff></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,0,255</TD>
    <TD>=3D</TD>
    <TD>324870</TD>
    <TD>510</TD>
    <TD>127</TD></TR>
  <TR>
    <TD>7</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#009600></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,150,0</TD>
    <TD>=3D</TD>
    <TD>252308</TD>
    <TD>405</TD>
    <TD>180</TD></TR>
  <TR>
    <TD>8</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#006400></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,100,0</TD>
    <TD>=3D</TD>
    <TD>202308</TD>
    <TD>355</TD>
    <TD>205</TD></TR>
  <TR>
    <TD>9</TD>
    <TD bgColor=3D#00ff00></TD>
    <TD bgColor=3D#00ffff></TD>
    <TD>0,255,0</TD>
    <TD>-</TD>
    <TD>0,255,255</TD>
    <TD>=3D</TD>
    <TD>194820</TD>
    <TD>255</TD>
    <TD>255</TD></TR>
  <TR>
    <TD>10</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#003200></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>0,50,0</TD>
    <TD>=3D</TD>
    <TD>172308</TD>
    <TD>305</TD>
    <TD>230</TD></TR>
  <TR>
    <TD>11</TD>
    <TD bgColor=3D#323264></TD>
    <TD bgColor=3D#c8c8c8></TD>
    <TD>50,50,100</TD>
    <TD>-</TD>
    <TD>200,200,200</TD>
    <TD>=3D</TD>
    <TD>171064</TD>
    <TD>400</TD>
    <TD>225</TD></TR>
  <TR>
    <TD>12</TD>
    <TD bgColor=3D#0000ff></TD>
    <TD bgColor=3D#ff00ff></TD>
    <TD>0,0,255</TD>
    <TD>-</TD>
    <TD>255,0,255</TD>
    <TD>=3D</TD>
    <TD>162308</TD>
    <TD>255</TD>
    <TD>255</TD></TR>
  <TR>
    <TD>13</TD>
    <TD bgColor=3D#00ff00></TD>
    <TD bgColor=3D#ffff00></TD>
    <TD>0,255,0</TD>
    <TD>-</TD>
    <TD>255,255,0</TD>
    <TD>=3D</TD>
    <TD>162308</TD>
    <TD>255</TD>
    <TD>255</TD></TR>
  <TR>
    <TD>14</TD>
    <TD bgColor=3D#7f7f7f></TD>
    <TD bgColor=3D#ffffff></TD>
    <TD>127,127,127</TD>
    <TD>-</TD>
    <TD>255,255,255</TD>
    <TD>=3D</TD>
    <TD>147392</TD>
    <TD>384</TD>
    <TD>192</TD></TR>
  <TR>
    <TD>15</TD>
    <TD bgColor=3D#7f7f7f></TD>
    <TD bgColor=3D#000000></TD>
    <TD>127,127,127</TD>
    <TD>-</TD>
    <TD>0,0,0</TD>
    <TD>=3D</TD>
    <TD>145097</TD>
    <TD>381</TD>
    <TD>190</TD></TR>
  <TR>
    <TD>16</TD>
    <TD bgColor=3D#646464></TD>
    <TD bgColor=3D#c8c8c8></TD>
    <TD>100,100,100</TD>
    <TD>-</TD>
    <TD>200,200,200</TD>
    <TD>=3D</TD>
    <TD>89960</TD>
    <TD>300</TD>
    <TD>150</TD></TR>
  <TR>
    <TD>17</TD>
    <TD bgColor=3D#7f7f7f></TD>
    <TD bgColor=3D#ffc864></TD>
    <TD>127,127,127</TD>
    <TD>-</TD>
    <TD>255,200,100</TD>
    <TD>=3D</TD>
    <TD>67948</TD>
    <TD>228</TD>
    <TD>164</TD></TR>
  <TR>
    <TD>18</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#640000></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>100,0,0</TD>
    <TD>=3D</TD>
    <TD>64661</TD>
    <TD>155</TD>
    <TD>155</TD></TR>
  <TR>
    <TD>19</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#960000></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>150,0,0</TD>
    <TD>=3D</TD>
    <TD>30749</TD>
    <TD>105</TD>
    <TD>105</TD></TR>
  <TR>
    <TD>20</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#c83200></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>200,50,0</TD>
    <TD>=3D</TD>
    <TD>18732</TD>
    <TD>105</TD>
    <TD>55</TD></TR>
  <TR>
    <TD>21</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#c80000></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>200,0,0</TD>
    <TD>=3D</TD>
    <TD>8732</TD>
    <TD>55</TD>
    <TD>55</TD></TR>
  <TR>
    <TD>22</TD>
    <TD bgColor=3D#7f7f7f></TD>
    <TD bgColor=3D#7f807f></TD>
    <TD>127,127,127</TD>
    <TD>-</TD>
    <TD>127,128,127</TD>
    <TD>=3D</TD>
    <TD>4</TD>
    <TD>1</TD>
    <TD>1</TD></TR>
  <TR>
    <TD>23</TD>
    <TD bgColor=3D#7f7f7f></TD>
    <TD bgColor=3D#7f7f80></TD>
    <TD>127,127,127</TD>
    <TD>-</TD>
    <TD>127,127,128</TD>
    <TD>=3D</TD>
    <TD>2</TD>
    <TD>1</TD>
    <TD>1</TD></TR>
  <TR>
    <TD>24</TD>
    <TD bgColor=3D#ff0000></TD>
    <TD bgColor=3D#ff0000></TD>
    <TD>255,0,0</TD>
    <TD>-</TD>
    <TD>255,0,0</TD>
    <TD>=3D</TD>
    <TD>0</TD>
    <TD>0</TD>
    <TD>0</TD></TR></TBODY></TABLE></FONT></DIV><FONT face=3DArial =
size=3D2>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Here is program which&nbsp;makes html&nbsp;table above:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- color difference test.ex<BR>-- test two-color-difference =
functions<BR>--=20
08. junij 2001 12:55, petek</DIV>
<DIV>&nbsp;</DIV>
<DIV>include sort.e</DIV>
<DIV>&nbsp;</DIV>
<DIV>constant output_file =3D "colordif.htm"</DIV>
<DIV>&nbsp;</DIV>
<DIV>function abs (atom x)<BR>&nbsp;if x &lt; 0 then return -x else =
return x end=20
if<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function RGB( integer r, integer g, integer b=20
)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; -- return RGB value of=20
triad<BR>&nbsp;&nbsp;&nbsp; return r + ( g * 256 ) + ( b * 256 * 256 )=20
<BR>&nbsp;&nbsp;&nbsp; <BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- returns html color string<BR>function rgb_to_html (sequence=20
rgb)&nbsp;<BR>&nbsp;--// sequence ret<BR>&nbsp;--// ret =3D sprintf =
("%x", RGB=20
(rgb [1], rgb [2], rgb [3]))<BR>&nbsp;--// ret =3D repeat ('0', length =
("000000")=20
- length (ret)) &amp; ret<BR>&nbsp;--// return ret</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;sequence ret, t<BR>&nbsp;ret&nbsp; =3D "#000000"<BR>&nbsp;t =
=3D sprintf=20
("%x", rgb [1])<BR>&nbsp;ret [2..3] =3D repeat ('0', 2 - length (t)) =
&amp;=20
t<BR>&nbsp;t =3D sprintf ("%x", rgb [2])<BR>&nbsp;ret [4..5] =3D repeat =
('0', 2 -=20
length (t)) &amp; t<BR>&nbsp;t =3D sprintf ("%x", rgb [3])<BR>&nbsp;ret =
[6..7] =3D=20
repeat ('0', 2 - length (t)) &amp; t<BR>&nbsp;return ret<BR>end =
function</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- function by&nbsp; Mic<BR>-- return values are 0 - 512k =
(approx)<BR>--=20
just do "? weighted_match({0,0,0}, {255,255,255})" to find out the =
maximum=20
distance<BR>--<BR>function weighted_distance(sequence rgb1, sequence=20
rgb2)<BR>&nbsp; integer rmean<BR>&nbsp; integer =
dr,dg,db<BR>&nbsp;<BR>&nbsp;=20
rmean =3D floor((rgb1[1] + rgb2[1]) / 2)<BR>&nbsp; dr =3D (rgb1[1] -=20
rgb2[1])<BR>&nbsp; dr *=3D dr<BR>&nbsp; dr =3D floor((dr * (512 + =
rmean)) /=20
256)<BR>&nbsp;<BR>&nbsp; dg =3D (rgb1[2] - rgb2[2])<BR>&nbsp; dg =3D (dg =
* dg)&nbsp;=20
* 4<BR>&nbsp; <BR>&nbsp; db =3D (rgb1[3] - rgb2[3])<BR>&nbsp; db *=3D =
db<BR>&nbsp;=20
db =3D floor((db * (767 - rmean)) / 256)<BR>&nbsp;<BR>&nbsp; return (dr =
+ dg +=20
db)<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- function by David Cuny<BR>function Cuny_color_difference =
(sequence rgb1,=20
sequence rgb2)<BR>&nbsp;&nbsp;&nbsp; atom diff<BR>&nbsp;&nbsp;&nbsp; =
diff =3D=20
0<BR>&nbsp;&nbsp;&nbsp; -- get difference for each =
rgb<BR>&nbsp;&nbsp;&nbsp; for=20
j =3D 1 to 3 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diff +=3D =
abs( rgb1[j]=20
- rgb2[j] )<BR>&nbsp;&nbsp;&nbsp; end for<BR>&nbsp;&nbsp;&nbsp; return=20
diff<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- Returns the difference between two colors.<BR>-- It should =
return the=20
biggest difference when colors are WHITE and BLACK.<BR>-- Examples (all =
assume=20
that 'color_importance' is 1):<BR>-- If colors are black{0, 0, 0} and =
white=20
{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.</DIV>
<DIV>&nbsp;</DIV>
<DIV>function reco_color_difference (sequence rgb1, sequence=20
rgb2)<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; -- The bigger this number is the =
more=20
important the brightness difference<BR>&nbsp;&nbsp;&nbsp; -- between the =
two=20
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<BR>&nbsp;&nbsp;&nbsp; atom ret<BR>&nbsp;&nbsp;&nbsp; =
integer=20
red1, green1, blue1, red2, green2, blue2<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; =

color_importance =3D 0.25<BR>&nbsp;&nbsp;&nbsp; brightness_importance =
=3D=20
0.5<BR>&nbsp;&nbsp;&nbsp; red1 =3D rgb1 [1]<BR>&nbsp;&nbsp;&nbsp; green1 =
=3D rgb1=20
[2]<BR>&nbsp;&nbsp;&nbsp; blue1 =3D rgb1 [3]<BR>&nbsp;&nbsp;&nbsp; red2 =
=3D rgb2=20
[1]<BR>&nbsp;&nbsp;&nbsp; green2 =3D rgb2 [2]<BR>&nbsp;&nbsp;&nbsp; =
blue2 =3D rgb2=20
[3]<BR>&nbsp;&nbsp;&nbsp; ret =3D=20
(<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
return ret<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>function sort_result (sequence s1, sequence s2)<BR>&nbsp;if s1 [3] =
[1] &gt;=20
s2 [3] [1] then return -1<BR>&nbsp;elsif s1 [3] [1] =3D s2 [3] [1] then =
return=20
0<BR>&nbsp;else return 1 end if<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- 'func_names' is sequence with all function names to =
test.<BR>procedure=20
test_functions (sequence func_names)<BR>&nbsp;atom =
diff<BR>&nbsp;sequence rgb1,=20
rgb2<BR>&nbsp;sequence func_ids<BR>&nbsp;sequence =
colors&nbsp;<BR>&nbsp;integer=20
fn<BR>&nbsp;-- 1. rgb1, 2. rgb2, 3. sequence {function differences, =
sorted by=20
first one}<BR>&nbsp;sequence result&nbsp;<BR>&nbsp;colors=20
=3D<BR>&nbsp;{<BR>&nbsp;&nbsp;{{255, 255, 255}, {0, 0, =
0}},<BR>&nbsp;&nbsp;{{127,=20
127, 127}, {0, 0, 0}},<BR>&nbsp;&nbsp;{{127, 127, 127}, {255, 255,=20
255}},<BR>&nbsp;&nbsp;{{127, 127, 127}, {127, 128, =
127}},<BR>&nbsp;&nbsp;{{127,=20
127, 127}, {127, 127, 128}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {255, 0,=20
0}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {0, 255, 0}},<BR>&nbsp;&nbsp;{{255, 0, =
0}, {0,=20
0, 255}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {0, 255, =
255}},<BR>&nbsp;&nbsp;{{255, 0,=20
0}, {255, 255, 255}},<BR>&nbsp;&nbsp;{{0, 255, 0}, {0, 255,=20
255}},<BR>&nbsp;&nbsp;{{0, 0, 255}, {255, 0, 255}},<BR>&nbsp;&nbsp;{{0, =
255, 0},=20
{255, 255, 0}},<BR>&nbsp;&nbsp;{{127, 127, 127}, {255, 200,=20
100}},<BR>&nbsp;&nbsp;{{100, 100, 100}, {200, 200, =
200}},<BR>&nbsp;&nbsp;{{50,=20
50, 100}, {200, 200, 200}},<BR>&nbsp;&nbsp;{{0, 50, 0}, {200, 255,=20
200}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {200, 0, 0}},<BR>&nbsp;&nbsp;{{255, =
0, 0},=20
{150, 0, 0}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {100, 0, =
0}},<BR>&nbsp;&nbsp;{{255,=20
0, 0}, {200, 50, 0}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {0, 50,=20
0}},<BR>&nbsp;&nbsp;{{255, 0, 0}, {0, 150, 0}},<BR>&nbsp;&nbsp;{{255, 0, =
0}, {0,=20
100, 0}}<BR>&nbsp;}<BR>&nbsp;result =3D repeat (repeat (0, 3), length=20
(colors))<BR>&nbsp;fn =3D open (output_file, "w")<BR>&nbsp;puts (fn,=20
"&lt;html&gt;&lt;body&gt;\n")<BR>&nbsp;func_ids =3D repeat (0, length=20
(func_names))<BR>&nbsp;for i =3D 1 to length (func_names)=20
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;func_ids [i] =3D =
routine_id=20
(func_names [i])<BR>&nbsp;end for&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;for i =3D 1 to length (colors) do<BR>&nbsp;&nbsp;rgb1 =3D =
colors [i]=20
[1]<BR>&nbsp;&nbsp;rgb2 =3D colors [i] [2]<BR>&nbsp;&nbsp;result [i] [1] =
=3D=20
rgb1<BR>&nbsp;&nbsp;result [i] [2] =3D rgb2<BR>&nbsp;&nbsp;result [i] =
[3] =3D repeat=20
(0, length (func_names))<BR>&nbsp;&nbsp;-- each =
function<BR>&nbsp;&nbsp;for j =3D=20
1 to length (func_ids) do<BR>&nbsp;&nbsp;&nbsp;diff =3D call_func =
(func_ids [j],=20
{rgb1, rgb2})<BR>&nbsp;&nbsp;&nbsp;result [i] [3] [j] =3D =
diff<BR>&nbsp;&nbsp;end=20
for<BR>&nbsp;end for</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;result =3D custom_sort (routine_id ("sort_result"), =
result)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;-- print sorted results<BR>&nbsp;puts (fn, "&lt;table=20
border=3D1&gt;\n")<BR>&nbsp;-- column headers&nbsp;<BR>&nbsp;puts (fn,=20
"&lt;tr&gt;\n")<BR>&nbsp;puts (fn, =
"&lt;td&gt;&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;see1&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;see2&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;color1&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;-&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;color2&lt;/td&gt;\n")<BR>&nbsp;puts (fn,=20
"&lt;td&gt;=3D&lt;/td&gt;\n")<BR>&nbsp;for i =3D 1 to length =
(func_names)=20
do&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;if i =3D 1=20
then<BR>&nbsp;&nbsp;&nbsp;puts (fn, "&lt;td&gt;&lt;b&gt;" &amp; =
func_names [i]=20
&amp; =
"&lt;/b&gt;&lt;/td&gt;\n")<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;puts =

(fn, "&lt;td&gt;" &amp; func_names [i] &amp; =
"&lt;/td&gt;\n")<BR>&nbsp;&nbsp;end=20
if<BR>&nbsp;end for<BR>&nbsp;puts (fn, =
"&lt;/tr&gt;\n\n")<BR>&nbsp;printf (fn,=20
"%s", {"\n\n"})</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;for i =3D 1 to length (result) do<BR>&nbsp;&nbsp;rgb1 =3D =
result [i]=20
[1]<BR>&nbsp;&nbsp;rgb2 =3D result [i] [2]</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;puts (fn, "&lt;tr&gt;\n")<BR>&nbsp;&nbsp;printf (fn,=20
"&lt;td&gt;%d&lt;/td&gt;\n", i)<BR>&nbsp;&nbsp;puts (fn, "&lt;td =
bgcolor=3D" &amp;=20
rgb_to_html (rgb1) &amp; "&gt;&lt;/td&gt;\n")<BR>&nbsp;&nbsp;puts (fn, =
"&lt;td=20
bgcolor=3D" &amp; rgb_to_html (rgb2) &amp;=20
"&gt;&lt;/td&gt;\n")<BR>&nbsp;&nbsp;printf (fn,=20
"&lt;td&gt;%d,%d,%d&lt;/td&gt;\n", {rgb1 [1], rgb1 [2], rgb1=20
[3]})<BR>&nbsp;&nbsp;puts (fn, =
"&lt;td&gt;-&lt;/td&gt;\n")<BR>&nbsp;&nbsp;printf=20
(fn, "&lt;td&gt;%d,%d,%d&lt;/td&gt;\n", {rgb2 [1], rgb2 [2], rgb2=20
[3]})<BR>&nbsp;&nbsp;puts (fn, =
"&lt;td&gt;=3D&lt;/td&gt;\n")<BR>&nbsp;&nbsp;for j=20
=3D 1 to length (func_names) do<BR>&nbsp;&nbsp;&nbsp;printf (fn,=20
"&lt;td&gt;%d&lt;/td&gt;\n", floor (result [i] [3] =
[j]))<BR>&nbsp;&nbsp;end=20
for<BR>&nbsp;&nbsp;puts (fn, "&lt;/tr&gt;\n\n")<BR>&nbsp;end for</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;puts (fn, "&lt;/table&gt;")<BR>&nbsp;puts (fn,=20
"&lt;/body&gt;&lt;/html&gt;\n")<BR>&nbsp;close (fn)<BR>&nbsp;puts (1, =
"Done! See=20
file " &amp; output_file &amp; ".\n")<BR>end procedure</DIV>
<DIV>&nbsp;</DIV>
<DIV>test_functions ({"weighted_distance", "Cuny_color_difference",=20
"reco_color_difference"})</DIV>

------=_NextPart_000_0018_01C0F057.414A8E40--

new topic     » goto parent     » topic index » view message » categorize

5. Re: difference between two colors

Actually, I think #13 (green - yellow) *should* be greater than #14 (gray - 
white). The function I posted is based on quite a lot of research by <forgot 
his name>, and does take into account that e.g. blue and green are percieved 
differently by the human eye.

new topic     » goto parent     » topic index » view message » categorize

6. Re: difference between two colors

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>--&nbsp;&nbsp;&nbsp; 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>--&nbsp;&nbsp; 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>--&nbsp;&nbsp; 0 + 0 + 0 + brightness_importance * =
127 *=20
  3<BR>--&nbsp;&nbsp;&nbsp; =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>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; -- The bigger this =
number is=20
  the more important the brightness difference<BR>&nbsp;&nbsp;&nbsp; -- =
between=20
  the 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;=20
  atom 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=20
  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 =

  (color1)<BR>&nbsp;&nbsp;&nbsp; blue1 =3D GetBValue=20
  (color1)<BR>&nbsp;&nbsp;&nbsp; red2 =3D GetRValue =
(color2)<BR>&nbsp;&nbsp;&nbsp;=20
  green2 =3D GetGValue (color2)<BR>&nbsp;&nbsp;&nbsp; blue2 =3D =
GetBValue=20
  (color2)<BR>&nbsp;&nbsp;&nbsp; ret =3D=20
  =
(<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
  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--

new topic     » goto parent     » topic index » view message » categorize

7. Re: difference between two colors

Are you saying this serious?

Best Regards,
   Guillermo BonvehĂ­

PD: R Red G Green B Blue


--- rforno at tutopia.com wrote:
> 
> 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 ----- 
>   From: Tone Skoda 
>   To: EUforum 
>   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 =
> brightness_importance * 765.
>   -- If colors are red {255, 0, 0} and green {0, 255, 0} it returns:
>   --   255 + 255 + 0 + brightness_importance * 0 = 255 + 255 = 510.
>   -- If colors are gray {127, 127, 127} and black {0, 0, 0} it
> returns:
>   --   0 + 0 + 0 + brightness_importance * 127 * 3
>   --    = 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 =
>   -- = 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.   
>       atom color_importance
>       atom ret
>       integer red1, green1, blue1, red2, green2, blue2
> 
>       color_importance = 0.25
>       brightness_importance = 0.5
>       red1 = GetRValue (color1)
>       green1 = GetGValue (color1)
>       blue1 = GetBValue (color1)
>       red2 = GetRValue (color2)
>       green2 = GetGValue (color2)
>       blue2 = GetBValue (color2)
>       ret = (
>               color_importance * (
<snip>

> 
> 
> 

=====
Best Regards,
    Guillermo Bonvehi
    AKA: Knixeur - Caballero Rojo

new topic     » goto parent     » topic index » view message » categorize

8. Re: difference between two colors

----- Original Message -----
From: rforno at tutopia.com
Subject: Re: difference between two colors


>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...


This seems reasonable, especially when you factor in the way the eye
perceives colors. Here's one attempt at this algorithm.

----------------------------
function RFORNO_difference(sequence rgb1, sequence rgb2)

    sequence colorfactors
    atom diff, brightness

    -- Set color band ranges
    -- ie. Red needs 16 values difference before the eye registers it,
    --     Green needs 12, and Blue needs 10
    colorfactors = {16, 12, 10}

    -- Set brightness factor
    -- Tune this to your liking.
    brightness = 1.0

    -- Calc relative luminosity difference of raw colors.
    lum = abs((rgb1[1] + rgb1[2] + rgb1[3])-(rgb2[1] + rgb2[2] + rgb2[3]))

    -- Adjust raw colors into color bands.
    rgb1 = floor(rgb1 / colorfactors) * colorfactors
    rgb2 = floor(rgb2 / colorfactors) * colorfactors

    -- Calc 3d-space distance.
    diff = power( power(rgb1[1] - rgb2[1], 2) +
                  power(rgb1[2] - rgb2[2], 2) +
                  power(rgb1[3] - rgb2[3], 2)
            , 0.5)

    -- Adjust dist with brightness,
    -- Convert to integer and return
    return floor(diff + (lum * brightness))

end function
----------------------------

Of course, one could also debate the color band factors, as each person sees
color differently. There is an interesting discussion on this at
http://www.firelily.com/opinions/color.html


---
cheers,
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

new topic     » goto parent     » topic index » view message » categorize

9. Re: difference between two colors

My mistake. I meant difference n. 17 should be greater than n. 16.

----- Original Message -----
From: <stabmaster_ at HOTMAIL.COM>
Subject: Re: difference between two colors


>
>
> Actually, I think #13 (green - yellow) *should* be greater than #14
(gray -
> white). The function I posted is based on quite a lot of research by
<forgot
> his name>, and does take into account that e.g. blue and green are
percieved
> differently by the human eye.
>
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

10. Re: difference between two colors


new topic     » goto parent     » topic index » view message » categorize

11. Re: difference between two colors


new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu