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 function to be as similar =
as possible=20
to the way that human eye sees it.</FONT></DIV>
<DIV> </DIV>
<DIV> </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> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Here is program which makes html table above:</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>-- color difference test.ex<BR>-- test two-color-difference =
functions<BR>--=20
08. junij 2001 12:55, petek</DIV>
<DIV> </DIV>
<DIV>include sort.e</DIV>
<DIV> </DIV>
<DIV>constant output_file =3D "colordif.htm"</DIV>
<DIV> </DIV>
<DIV>function abs (atom x)<BR> if x < 0 then return -x else =
return x end=20
if<BR>end function</DIV>
<DIV> </DIV>
<DIV>global function RGB( integer r, integer g, integer b=20
)<BR> <BR> -- return RGB value of=20
triad<BR> return r + ( g * 256 ) + ( b * 256 * 256 )=20
<BR> <BR>end function</DIV>
<DIV> </DIV>
<DIV>-- returns html color string<BR>function rgb_to_html (sequence=20
rgb) <BR> --// sequence ret<BR> --// ret =3D sprintf =
("%x", RGB=20
(rgb [1], rgb [2], rgb [3]))<BR> --// ret =3D repeat ('0', length =
("000000")=20
- length (ret)) & ret<BR> --// return ret</DIV>
<DIV> </DIV>
<DIV> sequence ret, t<BR> ret =3D "#000000"<BR> t =
=3D sprintf=20
("%x", rgb [1])<BR> ret [2..3] =3D repeat ('0', 2 - length (t)) =
&=20
t<BR> t =3D sprintf ("%x", rgb [2])<BR> ret [4..5] =3D repeat =
('0', 2 -=20
length (t)) & t<BR> t =3D sprintf ("%x", rgb [3])<BR> ret =
[6..7] =3D=20
repeat ('0', 2 - length (t)) & t<BR> return ret<BR>end =
function</DIV>
<DIV> </DIV>
<DIV>-- function by 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> integer rmean<BR> integer =
dr,dg,db<BR> <BR> =20
rmean =3D floor((rgb1[1] + rgb2[1]) / 2)<BR> dr =3D (rgb1[1] -=20
rgb2[1])<BR> dr *=3D dr<BR> dr =3D floor((dr * (512 + =
rmean)) /=20
256)<BR> <BR> dg =3D (rgb1[2] - rgb2[2])<BR> dg =3D (dg =
* dg) =20
* 4<BR> <BR> db =3D (rgb1[3] - rgb2[3])<BR> db *=3D =
db<BR> =20
db =3D floor((db * (767 - rmean)) / 256)<BR> <BR> return (dr =
+ dg +=20
db)<BR>end function</DIV>
<DIV> </DIV>
<DIV>-- function by David Cuny<BR>function Cuny_color_difference =
(sequence rgb1,=20
sequence rgb2)<BR> atom diff<BR> =
diff =3D=20
0<BR> -- get difference for each =
rgb<BR> for=20
j =3D 1 to 3 do<BR> diff +=3D =
abs( rgb1[j]=20
- rgb2[j] )<BR> end for<BR> return=20
diff<BR>end function</DIV>
<DIV> </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>-- 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>-- =
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>-- 0 + 0 =
+ 0 +=20
brightness_importance * 127 * 3<BR>-- =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> </DIV>
<DIV>function reco_color_difference (sequence rgb1, sequence=20
rgb2)<BR> <BR> -- The bigger this number is the =
more=20
important the brightness difference<BR> -- between the =
two=20
colors is.<BR> atom=20
brightness_importance<BR> -- Color importance. Modify =
these=20
two values if neccessary in the future. =
<BR> atom=20
color_importance<BR> atom ret<BR> =
integer=20
red1, green1, blue1, red2, green2, blue2<BR> <BR> =
color_importance =3D 0.25<BR> brightness_importance =
=3D=20
0.5<BR> red1 =3D rgb1 [1]<BR> green1 =
=3D rgb1=20
[2]<BR> blue1 =3D rgb1 [3]<BR> red2 =
=3D rgb2=20
[1]<BR> green2 =3D rgb2 [2]<BR> =
blue2 =3D rgb2=20
[3]<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</DIV>
<DIV> </DIV>
<DIV>function sort_result (sequence s1, sequence s2)<BR> if s1 [3] =
[1] >=20
s2 [3] [1] then return -1<BR> elsif s1 [3] [1] =3D s2 [3] [1] then =
return=20
0<BR> else return 1 end if<BR>end function</DIV>
<DIV> </DIV>
<DIV>-- 'func_names' is sequence with all function names to =
test.<BR>procedure=20
test_functions (sequence func_names)<BR> atom =
diff<BR> sequence rgb1,=20
rgb2<BR> sequence func_ids<BR> sequence =
colors <BR> integer=20
fn<BR> -- 1. rgb1, 2. rgb2, 3. sequence {function differences, =
sorted by=20
first one}<BR> sequence result <BR> colors=20
=3D<BR> {<BR> {{255, 255, 255}, {0, 0, =
0}},<BR> {{127,=20
127, 127}, {0, 0, 0}},<BR> {{127, 127, 127}, {255, 255,=20
255}},<BR> {{127, 127, 127}, {127, 128, =
127}},<BR> {{127,=20
127, 127}, {127, 127, 128}},<BR> {{255, 0, 0}, {255, 0,=20
0}},<BR> {{255, 0, 0}, {0, 255, 0}},<BR> {{255, 0, =
0}, {0,=20
0, 255}},<BR> {{255, 0, 0}, {0, 255, =
255}},<BR> {{255, 0,=20
0}, {255, 255, 255}},<BR> {{0, 255, 0}, {0, 255,=20
255}},<BR> {{0, 0, 255}, {255, 0, 255}},<BR> {{0, =
255, 0},=20
{255, 255, 0}},<BR> {{127, 127, 127}, {255, 200,=20
100}},<BR> {{100, 100, 100}, {200, 200, =
200}},<BR> {{50,=20
50, 100}, {200, 200, 200}},<BR> {{0, 50, 0}, {200, 255,=20
200}},<BR> {{255, 0, 0}, {200, 0, 0}},<BR> {{255, =
0, 0},=20
{150, 0, 0}},<BR> {{255, 0, 0}, {100, 0, =
0}},<BR> {{255,=20
0, 0}, {200, 50, 0}},<BR> {{255, 0, 0}, {0, 50,=20
0}},<BR> {{255, 0, 0}, {0, 150, 0}},<BR> {{255, 0, =
0}, {0,=20
100, 0}}<BR> }<BR> result =3D repeat (repeat (0, 3), length=20
(colors))<BR> fn =3D open (output_file, "w")<BR> puts (fn,=20
"<html><body>\n")<BR> func_ids =3D repeat (0, length=20
(func_names))<BR> for i =3D 1 to length (func_names)=20
do<BR> func_ids [i] =3D =
routine_id=20
(func_names [i])<BR> end for </DIV>
<DIV> </DIV>
<DIV> for i =3D 1 to length (colors) do<BR> rgb1 =3D =
colors [i]=20
[1]<BR> rgb2 =3D colors [i] [2]<BR> result [i] [1] =
=3D=20
rgb1<BR> result [i] [2] =3D rgb2<BR> result [i] =
[3] =3D repeat=20
(0, length (func_names))<BR> -- each =
function<BR> for j =3D=20
1 to length (func_ids) do<BR> diff =3D call_func =
(func_ids [j],=20
{rgb1, rgb2})<BR> result [i] [3] [j] =3D =
diff<BR> end=20
for<BR> end for</DIV>
<DIV> </DIV>
<DIV> result =3D custom_sort (routine_id ("sort_result"), =
result)</DIV>
<DIV> </DIV>
<DIV> -- print sorted results<BR> puts (fn, "<table=20
border=3D1>\n")<BR> -- column headers <BR> puts (fn,=20
"<tr>\n")<BR> puts (fn, =
"<td></td>\n")<BR> puts (fn,=20
"<td>see1</td>\n")<BR> puts (fn,=20
"<td>see2</td>\n")<BR> puts (fn,=20
"<td>color1</td>\n")<BR> puts (fn,=20
"<td>-</td>\n")<BR> puts (fn,=20
"<td>color2</td>\n")<BR> puts (fn,=20
"<td>=3D</td>\n")<BR> for i =3D 1 to length =
(func_names)=20
do <BR> if i =3D 1=20
then<BR> puts (fn, "<td><b>" & =
func_names [i]=20
& =
"</b></td>\n")<BR> else<BR> puts =
(fn, "<td>" & func_names [i] & =
"</td>\n")<BR> end=20
if<BR> end for<BR> puts (fn, =
"</tr>\n\n")<BR> printf (fn,=20
"%s", {"\n\n"})</DIV>
<DIV> </DIV>
<DIV> for i =3D 1 to length (result) do<BR> rgb1 =3D =
result [i]=20
[1]<BR> rgb2 =3D result [i] [2]</DIV>
<DIV> </DIV>
<DIV> puts (fn, "<tr>\n")<BR> printf (fn,=20
"<td>%d</td>\n", i)<BR> puts (fn, "<td =
bgcolor=3D" &=20
rgb_to_html (rgb1) & "></td>\n")<BR> puts (fn, =
"<td=20
bgcolor=3D" & rgb_to_html (rgb2) &=20
"></td>\n")<BR> printf (fn,=20
"<td>%d,%d,%d</td>\n", {rgb1 [1], rgb1 [2], rgb1=20
[3]})<BR> puts (fn, =
"<td>-</td>\n")<BR> printf=20
(fn, "<td>%d,%d,%d</td>\n", {rgb2 [1], rgb2 [2], rgb2=20
[3]})<BR> puts (fn, =
"<td>=3D</td>\n")<BR> for j=20
=3D 1 to length (func_names) do<BR> printf (fn,=20
"<td>%d</td>\n", floor (result [i] [3] =
[j]))<BR> end=20
for<BR> puts (fn, "</tr>\n\n")<BR> end for</DIV>
<DIV> </DIV>
<DIV> puts (fn, "</table>")<BR> puts (fn,=20
"</body></html>\n")<BR> close (fn)<BR> puts (1, =
"Done! See=20
file " & output_file & ".\n")<BR>end procedure</DIV>
<DIV> </DIV>
<DIV>test_functions ({"weighted_distance", "Cuny_color_difference",=20
"reco_color_difference"})</DIV>
------=_NextPart_000_0018_01C0F057.414A8E40--