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!]