Re: lingo-l GetPixel() to compare colors

2003-06-06 Thread James Newton
On Wednesday, June 4, 2003, at 01:53 PM, Rodrigo Peres wrote:
I'm using getPixel to compare 2 images and return the 
differences between
them. After I run a list of points and check if some points are 
diferent
from the bgcolor (white). The problem: The image is scanned so 
there's a lot
of dust confusing the getPixel(). There's a way to compare if 
colors are
greater than or darker than??? Example
My background color is white (255,255,255) and if the pixel I 
test is close
to gray or black (0,0,0) it is diferent.
Hi Rodrigo,

If you need to compare a large number of pixels, you will find 
it much faster to use copyPixels() rather than getPixels().  
CopyPixels() is like a SCUBA diver: it can dive into Director's 
C++ imaging routines and do a lot of work on a lot of pixels at 
once.  GetPixel() is like a skin diver: it wastes a lot of time 
coming back up to Lingo for air between each operation.

You'll find below a handler that might be useful to you.

It compares two images and returns an integer in the range -1 - 
255.  A value of -1 indicates that the images are different 
sizes; a value of 0 indicates that they are identical.  Any 
other value indicates the maximum difference between any two 
identically placed pixels.

For example, if the two images are identical except for one 
pixel which is white in one image and black in the other, the 
output will be 255.  The same output value of 255 could occur 
for white+black, red+yellow, green+blue, and a number of other 
mis-matches.  The value reflects the biggest difference in 
either the red, green or blue values for the mis-matching pixels.

On the other hand, if one image shows white clouds and the other 
a snowy landscape, the output may be only (say) 89.  This would 
indicate that no identically placed pixels have that great a 
difference in color, even though the images themselves appear 
completely different to us humans.

You could run a number of tests on different scans of the same 
image to determine what level of tolerance you need to apply.  
You could then use the handler to compare images, and reject 
pairs whose tolerance exceeds your chosen value.

If you need to compare the contents of the images, you could 
break the images up into smaller sections and compare these.

Cheers,

James

--

on getTolerance(anImage, anotherImage) ---
  -- INPUT: anImage and anotherImage must both be image objects of
  -- the same size.
  -- OUTPUT: An integer indicating the maximum difference in red,
  -- green or blue for any individual pixel in the two images.
  -- If the images are identical, 0 is returned.  If the
  -- images are different sizes, -1 is returned.
  
  -- Ensure that the two images are the same size
  tRect = anImage.rect
  if anotherImage.rect  tRect then
return -1
  end if
  -- Create a 32-bit image in which to perform comparisons
  tCompare = image(tRect.width, tRect.height, 32)
  tCompare.copyPixels(anImage, tRect, tRect)
  -- Create an image which shows the differences between the images
  tCompare.copyPixels(anOtherImage, tRect, tRect, [#ink: #reverse])
  if not tCompare.trimWhiteSpace().width then
-- Images are identical
return 0
  end if
  tPixel = image(1, 1, 32)
  tWidth = 1
  tIncrement = 128
  -- Test in 8 steps of increasing precision
  repeat while tIncrement
if tWidth then
  -- Not enough attenuation was used for the last test
  tTolerance = tTolerance + tIncrement
else
  -- Check whether too much attenuation was used for the last test
  tTolerance = tTolerance - tIncrement
end if
-- Attenuate the difference image and check if all pixels go white
tPixel.setPixel(0, 0, rgb(tTolerance, tTolerance, tTolerance))
tTest  = tCompare.duplicate()
tTest.copyPixels(tPixel, tRect, rect(0,0,1,1), [#ink: #addPin])
tTest  = tTest.trimWhiteSpace()
tWidth = tTest.width -- will be zero if all pixels are now white
-- Increase the precision for the next test
tIncrement = tIncrement / 2
  end repeat
  return tTolerance + (tWidth  0) -- + 1 if last test failed
end getTolerance
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-06 Thread 2702NET
BTW, if you don't have James' book I highly recommend it. Plenty of  
nice imaging lingo stuff. Kerry's and Gretchen's reviews at Amazon say  
it all.

http://www.amazon.com/exec/obidos/tg/detail/-/0072132655/104-9270019- 
9338345?vi=glance

Joe

On Thursday, Jun 5, 2003, at 12:01 US/Eastern, James Newton wrote:

Hi Rodrigo,

If you need to compare a large number of pixels, you will find it much  
faster to use copyPixels() rather than getPixels().  CopyPixels() is  
like a SCUBA diver: it can dive into Director's C++ imaging routines  
and do a lot of work on a lot of pixels at once.  GetPixel() is like a  
skin diver: it wastes a lot of time coming back up to Lingo for air  
between each operation.
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


lingo-l GetPixel() to compare colors

2003-06-05 Thread Rodrigo Peres
Hi list,

I'm using getPixel to compare 2 images and return the differences between
them. After I run a list of points and check if some points are diferent
from the bgcolor (white). The problem: The image is scanned so there's a lot
of dust confusing the getPixel(). There's a way to compare if colors are
greater than or darker than??? Example
My background color is white (255,255,255) and if the pixel I test is close
to gray or black (0,0,0) it is diferent.


Thank's

Rodrigo

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Howdy-Tzi
On Wednesday, Jun 4, 2003, at 08:53 America/Chicago, Rodrigo Peres 
wrote:

There's a way to compare if colors are
greater than or darker than???
Try using color objects and palette index conversions:

oColor = color(#rgb, 255,255,255)
oColor2 = color(#rgb, 0,0,0)
put oColor.paletteIndex  oColor2.paletteIndex
-- 0
put oColor.paletteIndex  oColor2.paletteIndex
-- 1
Warren Ockrassa | President,  nightwares LLC  [EMAIL PROTECTED]
 nightwares LLC | Consulting  Programming http://www.nightwares.com/
  Developer | Structor, a presentation development/programming tool
  Info and demo | http://www.nightwares.com/structor/
 Author | Director 8.5 Shockwave Studio: A Beginner's Guide
Chapter samples | http://www.nightwares.com/director_beginners_guide/
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Carl West
Howdy-Tzi wrote:
 
 On Wednesday, Jun 4, 2003, at 08:53 America/Chicago, Rodrigo Peres
 wrote:
 
  There's a way to compare if colors are
  greater than or darker than???
 
 Try using color objects and palette index conversions:
 
 oColor = color(#rgb, 255,255,255)
 oColor2 = color(#rgb, 0,0,0)
 put oColor.paletteIndex  oColor2.paletteIndex
 -- 0
 put oColor.paletteIndex  oColor2.paletteIndex
 -- 1

Works in the extreme case, but it gets shaky in the middle values unless you're using 
the greyscale palette:

cyan = color(#rgb, 0, 255, 255)
dkcyan = color(#rgb, 0, 204, 255)
dkbrn = color(#rgb, 51, 0, 0)

-- System - Win palette
put cyan.paletteIndex 
-- 1
put dkbrn.paletteIndex
-- 179
put dkcyan.paletteIndex
-- 184

-- System - Mac palette
put cyan.paletteIndex 
-- 180
put dkbrn.paletteIndex
-- 179
put dkcyan.paletteIndex
-- 186


-- Greyscale palette
put cyan.paletteIndex 
-- 85
put dkbrn.paletteIndex
-- 238
put dkcyan.paletteIndex
-- 102

-- 
Carl West   [EMAIL PROTECTED]   http://eisen.home.attbi.com

I have no superfluous leisure; my stay must be stolen out
of other affairs; but I will attend you awhile.
   - Isabella, Measure for Measure, Act 3 Scene 1
-
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Cole Tierney
There's a way to compare if colors are
greater than or darker than???
Try using color objects and palette index conversions:

oColor = color(#rgb, 255,255,255)
oColor2 = color(#rgb, 0,0,0)
put oColor.paletteIndex  oColor2.paletteIndex
-- 0
put oColor.paletteIndex  oColor2.paletteIndex
-- 1
Curious. How does the color object know what palette to use? The 
movie's default palette? A coworker asked me the same question, just 
today.

--
Cole
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Colin Holgate
Here's a possibly good way to do it (I say possibly, because I didn't 
test it, but it feels like it ought to work). If you're using 8.5 or 
later, you could do this:

c1 = rgb(100,100,100)
c2 = rgb(123,100,100)
v1 = vector(c1.red,c1.green,c1.blue)
v2 = vector(c2.red,c2.green,c2.blue)
put v1.distanceto(v2)
-- 23.
You would count colors as being the same if their distance from the 
comparison color is less than a certain amount.



[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Howdy-Tzi
On Wednesday, Jun 4, 2003, at 12:10 America/Chicago, Cole Tierney wrote:

There's a way to compare if colors are
greater than or darker than???
Try using color objects and palette index conversions:

oColor = color(#rgb, 255,255,255)
oColor2 = color(#rgb, 0,0,0)
put oColor.paletteIndex  oColor2.paletteIndex
-- 0
put oColor.paletteIndex  oColor2.paletteIndex
-- 1
Curious. How does the color object know what palette to use?
Oops. Looks like MX has changed things a bit. Used to be that the 
paletteIndex value could return a number into the millions if you were 
at 24-bit + color.

HOWever, you can carry out the same comparisons using hexString():

oColor = color(#rgb, 0,0,0)
put oColor.hexstring()
-- #00
oColor2 = color(#rgb, 255,255,255)
put oColor2.hexString()
-- #FF
put oColor.hexString()  oColor2.hexString()
-- 0
put oColor.hexString()  oColor2.hexString()
-- 1
That should take care of any funky mid-shade colors.

Warren Ockrassa | President,  nightwares LLC  [EMAIL PROTECTED]
 nightwares LLC | Consulting  Programming http://www.nightwares.com/
  Developer | Structor, a presentation development/programming tool
  Info and demo | http://www.nightwares.com/structor/
 Author | Director 8.5 Shockwave Studio: A Beginner's Guide
Chapter samples | http://www.nightwares.com/director_beginners_guide/
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Colin Holgate
oColor = color(#rgb, 0,0,0)
put oColor.hexstring()
-- #00
oColor2 = color(#rgb, 255,255,255)
put oColor2.hexString()
-- #FF
put oColor.hexString()  oColor2.hexString()
-- 0
put oColor.hexString()  oColor2.hexString()
-- 1


Don't know if you would want to work this way. A color of 
rgb(0,255,255), full brightness cyan, may seem to be closer to black 
than rgb(1,0,0), almost completely black, would be.

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Carl West
Colin Holgate wrote:
 
 Here's a possibly good way to do it (I say possibly, because I didn't
 test it, but it feels like it ought to work). If you're using 8.5 or
 later, you could do this:
 
 c1 = rgb(100,100,100)
 c2 = rgb(123,100,100)
 v1 = vector(c1.red,c1.green,c1.blue)
 v2 = vector(c2.red,c2.green,c2.blue)
 put v1.distanceto(v2)
 -- 23.
 
 You would count colors as being the same if their distance from the
 comparison color is less than a certain amount.

Rodrigo asked:
 There's a way to compare if colors are
 greater than or darker than??? 

To compare lightness/darkness you'd need to get their distances from vector(0,0,0) and 
compare those

Just totaling the r,g, and b values should give a reasonable measure of the lightness 
of a pixel.

-- 
Carl West   [EMAIL PROTECTED]   http://eisen.home.attbi.com

I have no superfluous leisure; my stay must be stolen out
of other affairs; but I will attend you awhile.
   - Isabella, Measure for Measure, Act 3 Scene 1
-
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Cole Tierney
Here's a possibly good way to do it (I say possibly, because I 
didn't test it, but it feels like it ought to work). If you're using 
8.5 or later, you could do this:

c1 = rgb(100,100,100)
c2 = rgb(123,100,100)
v1 = vector(c1.red,c1.green,c1.blue)
v2 = vector(c2.red,c2.green,c2.blue)
put v1.distanceto(v2)
-- 23.
You would count colors as being the same if their distance from the 
comparison color is less than a certain amount.
Nice. This seems to make the most conceptual sense, since the rgb 
color model is described in terms of 3d space. Performance might be a 
problem, though.

--
Cole
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Colin Holgate
Nice. This seems to make the most conceptual sense, since the rgb 
color model is described in terms of 3d space. Performance might be 
a problem, though.


You could do your own Pythagoras out of the rgb values, and cut out 
the vector conversion. Not sure if that would be faster than the 
build in distanceto function.

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]


Re: lingo-l GetPixel() to compare colors

2003-06-05 Thread Howdy-Tzi
On Wednesday, Jun 4, 2003, at 13:36 America/Chicago, Colin Holgate 
wrote:

Don't know if you would want to work this way. A color of 
rgb(0,255,255), full brightness cyan, may seem to be closer to black 
than rgb(1,0,0), almost completely black, would be.
Sigh.

It's jut not my day it seems. You're right of course. This is what 
happens when I try to edit and think about code at the same time...

-- WthmO

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo.  Thanks!]