views:

33

answers:

2

Using Actionscript 3 is there a way to search one bitmap for the coordinates matching pixels of another bitmap?

http://dl.dropbox.com/u/1914/wired.png

Somehow you would have to loop through the bigger bitmap to find and the the pixel range that matches and return those coordinates. For example the Bitmap with the "E" is 250 pixels over and 14 pixels down in the bigger bitmap.

I haven't been able to come up with the solution on my own. Thanks.

A: 

There's no built-in way to do it, but if you don't mind using brute force then certainly AS3 gives you the tools you need. For example, you could loop through using the BitmapData.compare() function to compare the source image to a similarly-sized chunk of the target. If the two are identical, the returned BitmapData will be entirely black (you can quickly check whether this is true with getColorBoundsRect.) You could also speed this up a lot by initially checking only a few pixels with getPixel, or a few rows of pixels with getVector, and only checking the full images if they match.

That's all assuming that you don't need a fuzzy match, and that you don't mind an essentially brute-force solution. If either of those things isn't the case, then you'd better re-ask this as a general algorithm question. :D

fenomas
+1  A: 

As it has already been said there is no native function that allows you doing that, but you might want to have a look at Eugene Zatepyakin's ASSURF library: http://code.google.com/p/in-spirit/wiki/ASSURF - it will find your search template in the target material even if it is rotated, scaled or perspectively distorted.

Quasimondo
wow very cool stuff, thank you for sharing.
Cos