I want to stitch 2 images by crosscorrelation measure, but I don't want to use fft.
I tryed this but something seems to be wrong.any suggestions?
void test(IplImage* src,IplImage* temp)
{
double max_peak=0;
Point pt;
double per_x=0.5;
double per_y=0.5;
for(int cy=-h*per_y;cy<h*per_y;++cy)
{
for(int cx=-w*per_x;cx<w*per_x;++cx)
{
uchar* s_p= (uchar*) src->imageData;
uchar* t_p= (uchar*) temp->imageData;
__int64 suma=0;
__int64 sumb=0;
for(int y=0;y<h;++y)
{
for(int x=0;x<w;++x)
{
suma+= s_p[x];
if((y+cy)<h&&(x+cx)<w&&
(y+cy)>0&&(x+cx)>0)
sumb+= t_p[x+cx];
}
s_p+=w;
t_p+=w;
}
int meana = (int)(suma / (w * h)),
meanb = (int)(sumb / (w * h));
s_p= (uchar*) src->imageData;
t_p= (uchar*) temp->imageData;
__int64 corr = 0,
denoma = 0,
denomb = 0;
for(int y=0;y<h;++y)
{
for(int x=0;x<w;++x)
{
int da = (int)s_p[x] - meana;
int db= 0;
if((y+cy)<h&&(x+cx)<w&&
(y+cy)>0&&(x+cx)>0)
db = (int)t_p[x+cx] - meanb;
else
db= -meanb;
corr += da * db;
denoma += da * da;
denomb += db * db;
}
s_p+=w;
t_p+=w;
}
double peak= corr / sqrt( (double)denoma * denomb);
if (peak>max_peak)
{
pt.x= cx;
pt.y= cy;
max_peak=peak;
}
}
}
}