Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare two images and check equality

do you know any source or info about comparing images within as3/flash?

I want to compare two images and check if the images are the same or not.

Check this example: http://imageshack.us/photo/my-images/825/imagecompare.jpg/

Any clues? Thank you in advance!

like image 867
apak61 Avatar asked Nov 15 '12 16:11

apak61


2 Answers

In addition to the duplicate answers,

I believe you can also use BitmapData.compare()

An example taken from the link, consider the following two BitmapData objects:

 var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFF8800);
 var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCCC6600);
 var diffBmpData:BitmapData = bmd1.compare(bmd2) as BitmapData;
 trace ("0x" + diffBmpData.getPixel(0,0).toString(16); // 0x332200

Code Sample (for Percentage Difference) :

Don't how correct the results are, this is what I brewed up for a percentage :

var bmd1:BitmapData = new BitmapData(225, 225);
bmd1.draw(mc1);
var bmd2:BitmapData = new BitmapData(225, 225);
bmd2.draw(mc2);

var diffBmpData:BitmapData = bmd1.compare(bmd2) as BitmapData;

var diff:int = 0;
var total:int = 225 * 225;

for(var i=0; i<225; i++)
    for(var j=0; j<225; j++)
        diff += (diffBmpData.getPixel(i,j) != 0)? 1 : 0; 

info.text = Math.round((diff / total * 100)).toString();

where : info is a TextBox, mc1 & mc2 are two movieclips on stage.

I think you can make it better by comparing individual values (i.e how much different a pixel is) rather than a boolean is-pixel-similar match.


Result: (White space around the round image would be included)

enter image description here

like image 102
loxxy Avatar answered Sep 30 '22 07:09

loxxy


Using BitmapData.compare() will return 0 if the pixel values are identical.

trace(bmd1.compare(bmd2)); // 0
like image 44
xLite Avatar answered Sep 30 '22 07:09

xLite