I am searching for a way to identify similar png images with same size. The images are not the exact duplicates. For example If one image has a clip art of a bird, and another image has the same clip art but it is rotated, I want to identify both of them are similar. I want to write an algorithm do this using php.I have tried out this using javasript. What i am doing is convert the image into base64 and compare both the values using hamming distance. But as far I know this will not identify advanced techniques such as scaling, rotating. So what I want it to write an algorithm to do those things in php.Any ideas? This is what I have tried out using javascript and html5 canvas.
function newFunction()
{
var imageHeight = image.naturalHeight;
var imageWidth = image.naturalWidth;
var image2Height = image2.naturalHeight;
var image2Width = image2.naturalWidth;
var data3=[];
var imageData = context.getImageData(0,0,imageWidth,imageHeight);
var image2Data = context2.getImageData(0,0,image2Width,image2Height);
var data = imageData.data;
var data2 = image2Data.data;
function _arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
//str = String.fromCharCode.apply(null, data); // "ÿ8É"
// str2 = String.fromCharCode.apply(null, data2); // "ÿ8É"
// to Base64
b64 = _arrayBufferToBase64(data);
b64_2 = _arrayBufferToBase64(data2 );
console.log("64 base"+b64_2);
//
var toReturn = 0;
var firstBytes =new Uint8Array(1024);
var secondBytes=new Uint8Array(1024);
var different=new Uint8Array(1024);
// firstBytes = Convert.FromBase64String(first64);
// secondBytes = Convert.FromBase64String(second64);
different = 0;
var mylength;
if(b64.length>b64_2.length)
{
mylength=b64.length;
}
else
{
mylength=b64_2.length;
}
for (var index = 0; index < mylength; index++) {
different = (b64[index] ^ b64_2[index]);
while (different != 0) {
toReturn++;
different &= different - 1;
}
}
var percentage=(toReturn/((image2Height*image2Width)*2))*100;
if(percentage >=100)
{
percentage=100;
}
alert("Difference is "+percentage+" to return" +toReturn + " data1 length"+data.length+ " data2 length"+data2.length);
}
This function works well without any errors. But it won't recognized advanced features like scaling and rotating. Give me some ideas how to do this using php.