1. difference between two colors
- Posted by Tone Skoda <tone.skoda at siol.net> Jun 07, 2001
- 380 views
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> </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>-- 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.</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 the=20 more important the brightness difference<BR> -- = between the=20 two 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</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 = 0.25<BR> brightness_importance =3D = 0.5<BR> =20 red1 =3D GetRValue (color1)<BR> green1 =3D GetGValue=20 (color1)<BR> blue1 =3D GetBValue = (color1)<BR> =20 red2 =3D GetRValue (color2)<BR> green2 =3D GetGValue=20 (color2)<BR> blue2 =3D GetBValue = (color2)<BR> =20 ret =3D = (<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 ------=_NextPart_000_0015_01C0EF4C.34D80860--
2. Re: difference between two colors
- Posted by David Cuny <dcuny at LANSET.COM> Jun 07, 2001
- 371 views
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
3. Re: difference between two colors
- Posted by stabmaster_ at HOTMAIL.COM Jun 07, 2001
- 349 views
<html><DIV></DIV>>Can anyone think of any better function to get difference between two colors. <DIV></DIV>> <DIV> </DIV> <DIV>I use something like this:</DIV> <DIV> </DIV> <DIV> </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> integer rmean<BR> integer dr,dg,db</DIV> <DIV> </DIV> <DIV> rmean = floor((rgb1[1] + rgb2[1]) / 2)<BR> dr = (rgb1[1] - rgb2[1])<BR> dr *= dr<BR> dr = floor((dr * (512 + rmean)) / 256)</DIV> <DIV> </DIV> <DIV> dg = (rgb1[2] - rgb2[2])<BR> dg = (dg * dg) * 4</DIV> <DIV> </DIV> <DIV> db = (rgb1[3] - rgb2[3])<BR> db *= db<BR> db = floor((db * (767 - rmean)) / 256)</DIV> <DIV> </DIV> <DIV> return (dr + dg + db)</DIV> <DIV>end function</DIV>
4. Re: difference between two colors
- Posted by Tone Skoda <tone.skoda at siol.net> Jun 08, 2001
- 367 views
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--
5. Re: difference between two colors
- Posted by stabmaster_ at HOTMAIL.COM Jun 08, 2001
- 369 views
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.
6. Re: difference between two colors
- Posted by rforno at tutopia.com Jun 08, 2001
- 365 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--
7. Re: difference between two colors
- Posted by pampeano at ROCKETMAIL.COM Jun 08, 2001
- 365 views
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
8. Re: difference between two colors
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 09, 2001
- 389 views
----- 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."
9. Re: difference between two colors
- Posted by Tone Skoda <tone.skoda at siol.net> Jun 09, 2001
- 376 views
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. > > > > >