Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

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;
                                }
                        }
                }  
}
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

At the start of the inner loop, you assign

uchar* t_p= (uchar*) temp->imageData;

later on, you use it as

t_p[x+cx];

Aren't you missing the cy here?

share|improve this answer
add comment

Isn't that what the following function in OpenCV does? Be sure to check out the method param.

void cvMatchTemplate(const CvArr* image, const CvArr* templ, CvArr* result, int method)

share|improve this answer
    
cvMatchTemplate use DFT, I need to do it without fft. –  mrgloom Dec 12 '12 at 9:35
2  
Why would you not want to use FFT? Its just a faster implementation of DFT and shows no performance or quality loss. Is this a homework problem? –  Naresh Dec 12 '12 at 9:56
    
hmm. Had to go read the source. You are correct it does use fft. Just curious, why is that a limitation? –  Zigner Dec 12 '12 at 9:56
    
I want to check my fft implementation works just like original implementation and I want to do performance comparision.Also maybe it will be simpler to parallelize code without fft. –  mrgloom Dec 12 '12 at 10:10
    
@mrgloom Im not sure you will be able to beat doing a correlation without using the FFT. –  Mohammad Dec 13 '12 at 4:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.