|
Imaging lingo utility
From: "James Newton" <jnewton@cqm.co.uk>
To: <lingo-l@penworks.com>
Subject: Re: <lingo-l> Imaging lingo utility
> I've written a utility that will import the screen grabs, compare
> them against a key image, and crop each so that only the changed
> pixels remain. Now I'm looking to optimize it.
Hi Kurt,
Thanks to Macromedia's Werner Sharp, here is a handler that will
calculate the difference between two images. It takes roughly
750 ms to treat an 800x600 pixel image on a Pentium II at 400 MHz.
Hats off to Werner!
James
----------------------------------------------------------------------
on isolateDifferences(image1, image2) --------------------------------
-- Returns an image which represents the differences between
-- <image1> and <image2>.
--
-- PARAMETERS: <image1> and <image2> are expected to be images of
-- identical size, shape and color depth
--
-- This handler was generously sponsored by Werner Sharp.
--------------------------------------------------------------------
-- Determine dimensions
imageRect = image1.rect
-- 1. create copy of image1
delta = image1.duplicate()
-- 2. isolate different pixels as non-white
delta.copyPixels(image2, imageRect, imageRect, [#ink: #reverse])
-- 3. create 1-bit mask image and fill with solid black
theMask = image(imageRect.width, imageRect.height, 1)
theMask.fill(imageRect, rgb(0, 0, 0))
-- 4. copy only non-white pixels over to destination but at the
-- same time make them white so we're left with only white and
-- black pixels. The white ones are the different pixels, the
-- black pixels are the same.
options = [ \
#ink: #backgroundTransparent, \
#color: rgb(255, 255, 255), \
#bgcolor: rgb(255, 255, 255) \
]
theMask.copypixels(delta, imageRect, imageRect, options)
-- 5. invert the 1-bit mask
theMask.copypixels(theMask, imageRect, imageRect, [#ink: #notCopy])
-- 6. use theMask to copy only the different pixels over from image2
delta.fill(imageRect, rgb(255, 255, 255)) -- recyle delta
delta.copyPixels(image2, imageRect, imageRect, [#maskImage:theMask])
return delta
end isolateDifferences
|