My first idea was to essentially create a circle that encompasses the entire image, and then draw a straight line from one end of the circle, through the center, to another end, and count the number of pixels it encounters. Once it gets that number, it divides the number by the maximum possible (the distance between the top left corner and the bottom right corner of the image). Then repeat the process 360 times. Then do this again for the other image and compare the two arrays of numbers. Then it's a matter of comparing the arrays by offsetting one of them 360 times and I figured that one of the comparisons should return true. But it isn't, the method doesn't seem to be working how I thought it would.
Does anybody know of a better way to do this? The code I have at the moment is below.
#include <math.h>
#include <iostream>
unsigned char* cluster::getRotationBuffer()
{
unsigned char* hash = (unsigned char*)calloc(180, sizeof(unsigned char));
for (double i = 0; i < 360; i += 2)
{
double x = cos(i) + 1;
double y = sin(i) + 1;
//x += (x < 0 ? -1 : 1);
//y += (y < 0 ? -1 : 1);
onyxNumber counter = 0;
for (double iy = height / 2.0, ix = width / 2.0; iy < height && ix < width && iy > 0.0 && ix > 0.0; iy += y, ix += x)
{
if (getBit((int)round(ix), (int)round(iy))) ++counter;
}
for (double iy = height / 2.0, ix = width / 2.0; iy < height && ix < width && iy > 0.0 && ix > 0.0; iy -= y, ix -= x)
{
if (getBit((int)round(ix), (int)round(iy))) ++counter;
}
hash[(int)i / 2] = (unsigned char)((counter / (double)sqrt(width * width + height * height)) * 100.0);
}
for (int i = 0; i < 180; ++i)
{
std::cout << (int)hash[i] << ", ";
}
std::cout << "\n\n";
return hash;
}
bool cluster::compare(cluster zvalue)
{
unsigned char* hash = getRotationBuffer();
unsigned char* hash2 = zvalue.getRotationBuffer();
for (onyxNumber j = 0; j < 180; ++j)
{
onyxNumber counter = 0;
for (onyxNumber i = 0; i < 180; ++i)
{
if (abs((int)hash[i] - (int)hash2[(i + j) % 180]) > 5) ++counter;
}
if (counter < 30) std::cout << "Matching at offset " << j << ". Counter = " << counter << "\n"; else std::cout << j << " - Counter = " << counter << "\n";
}
free(hash);
free(hash2);
return false;
}


Sign In
Create Account


Back to top










