4 Replies Latest reply on Jun 13, 2006 1:41 AM by James Newton, ACP

    Imaging Lingo Analyzing Image Object

    BSpero Level 1
      Hello,
      I am working on a project that involves using a virtual brush to remove "dirt" from an object on stage. I use a behavior that basically creates an alpha channel wherever the person brushes, therefore showing the image below it. I am trying to determine a way to analyze the image to see how much dirt has been brushed off. The end result being I need to have the program act certain ways if there has been a good amount of dirt removed, and another way, if they have not brushed off the objects enough. Any ideas?

      - B
        • 1. Re: Imaging Lingo Analyzing Image Object
          Level 7
          Can you try copyPixelling your alpha channel into a 1 x 1 image object
          and check the colour of the pixel it contains against an acceptable range?
          • 2. Re: Imaging Lingo Analyzing Image Object
            Level 7
            The only thing that comes to mind is to scan the range of the image pixel by
            pixel using getPixel and look for the rgb color of pixels that are erased.
            You'd have to assume that only a certain color replaces pixels that are
            erased. I use white in my example but of course that would be impractical.
            So this is a starting point. If an imaging lingo guru out there has a way
            to figure out how to distinguish erased pixels from those in the alpha
            channel that are transparent that would make this work. It can be slow for
            large images but its all I had in my head at 7am.

            call it as a function: prnctWhite = ScanImage (member (3).image)

            on ScanImage img
            hgt = img.height
            wdt = img.width
            whiteCount = 0
            otherCount = 0
            repeat with x = 1 to hgt
            repeat with y = 1 to wdt
            pxl = img.getPixel (x, y)
            if pxl = rgb (255, 255, 255) then
            whiteCount = whiteCount + 1
            else
            otherCount = otherCount + 1
            end if
            end repeat
            end repeat

            return whiteCount.float / (whiteCount + otherCount)

            end
            --
            Craig Wollman
            Word of Mouth Productions

            phone 212 928 9581
            fax 212 928 9582
            159-00 Riverside Drive West #5H-70
            NY, NY 10032
            www.wordofmouthpros.com


            "BSpero" <webforumsuser@macromedia.com> wrote in message
            news:e6ik5s$bqk$1@forums.macromedia.com...
            > Hello,
            > I am working on a project that involves using a virtual brush to remove
            > "dirt" from an object on stage. I use a behavior that basically creates an
            > alpha channel wherever the person brushes, therefore showing the image
            > below
            > it. I am trying to determine a way to analyze the image to see how much
            > dirt
            > has been brushed off. The end result being I need to have the program act
            > certain ways if there has been a good amount of dirt removed, and another
            > way,
            > if they have not brushed off the objects enough. Any ideas?
            >
            > - B
            >


            • 3. Re: Imaging Lingo Analyzing Image Object
              Level 7
              By the way, a 32 bit 800x600 image took just over 4 seconds to scan on my
              700 mHz PC.

              --
              Craig Wollman
              Word of Mouth Productions

              phone 212 928 9581
              fax 212 928 9582
              159-00 Riverside Drive West #5H-70
              NY, NY 10032
              www.wordofmouthpros.com


              "BSpero" <webforumsuser@macromedia.com> wrote in message
              news:e6ik5s$bqk$1@forums.macromedia.com...
              > Hello,
              > I am working on a project that involves using a virtual brush to remove
              > "dirt" from an object on stage. I use a behavior that basically creates an
              > alpha channel wherever the person brushes, therefore showing the image
              > below
              > it. I am trying to determine a way to analyze the image to see how much
              > dirt
              > has been brushed off. The end result being I need to have the program act
              > certain ways if there has been a good amount of dirt removed, and another
              > way,
              > if they have not brushed off the objects enough. Any ideas?
              >
              > - B
              >


              • 4. Re: Imaging Lingo Analyzing Image Object
                James Newton, ACP Level 3
                on compareImages(anImage, anotherImage, aTolerance) ------------------
                -- INPUT: <anImage> and <anotherImage> must both be image objects
                -- <aTolerance> should be an integer in the range 0 - 255
                -- OUTPUT: TRUE if the two images are comparable, FALSE if not.
                -- Being comparable means being the same size and having no
                -- pixels whose value is more than <aTolerance> different
                -- for either red, green or blue. The greater the value for
                -- <aTolerance> the greater the allowed differences between
                -- the images.
                --------------------------------------------------------------------

                -- Ensure that the two images are the same size
                tRect = anImage.rect
                if anotherImage.rect <> tRect then
                return 0
                end if

                -- Create a color object that defines the maximum allowed difference
                -- in color before the two images are considered different.
                if integerP(aTolerance) then
                aTolerance = rgb(aTolerance, aTolerance, aTolerance)
                else
                aTolerance = rgb(0, 0, 0) -- images must be identical
                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])
                -- new(#bitmap).image = tCompare

                -- Create a pixel of the color that expresses the maximum allowed
                -- difference in color.
                tPixel = image(1, 1, 32)
                tPixel.setPixel(0, 0, aTolerance)

                -- Attenuate the differences by the tolerance amount
                tCompare.copyPixels(tPixel, tRect, rect(0,0,1,1), [#ink: #addPin])
                -- new(#bitmap).image = tCompare

                -- Reduce the attenuated comparison to its non-white pixels
                tCompare = tCompare.trimWhiteSpace()
                -- new(#bitmap).image = tCompare

                -- If there are any pixels left, the images are not similar
                return tCompare.width = 0
                end compareImages