Image Registration,met a trouble in transform the dft to log polar

asked 2013-09-27 23:41:05 -0600

lovepeipeia gravatar image

Image Registration Using Fourier Transform and Phase Correlation

I know that opencv has a function to get the shift value using phase correlation ,but can't get the scale variation and Angle of Rotation .

C++: Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window=noArray()))

when I tried to modify the code . I met a trouble in transform the dft to log polar.


here is the original code I tried to modify


\OpenCV2.4.3\opencv\modules\imgproc\src\phasecorr.cpp

cv::Point2d cv::phaseCorrelateRes(InputArray _src1, InputArray _src2, InputArray _window, double* response) { Mat src1 = _src1.getMat(); Mat src2 = _src2.getMat(); Mat window = _window.getMat();

CV_Assert( src1.type() == src2.type());
CV_Assert( src1.type() == CV_32FC1 || src1.type() == CV_64FC1 );
CV_Assert( src1.size == src2.size);

if(!window.empty())
{
    CV_Assert( src1.type() == window.type());
    CV_Assert( src1.size == window.size);
}

int M = getOptimalDFTSize(src1.rows);
int N = getOptimalDFTSize(src1.cols);

Mat padded1, padded2, paddedWin;

if(M != src1.rows || N != src1.cols)
{
    copyMakeBorder(src1, padded1, 0, M - src1.rows, 0, N - src1.cols, BORDER_CONSTANT, Scalar::all(0));
    copyMakeBorder(src2, padded2, 0, M - src2.rows, 0, N - src2.cols, BORDER_CONSTANT, Scalar::all(0));

    if(!window.empty())
    {
        copyMakeBorder(window, paddedWin, 0, M - window.rows, 0, N - window.cols, BORDER_CONSTANT, Scalar::all(0));
    }
}
else
{
    padded1 = src1;
    padded2 = src2;
    paddedWin = window;
}

Mat FFT1, FFT2, P, Pm, C;

// perform window multiplication if available
if(!paddedWin.empty())
{
    // apply window to both images before proceeding...
    multiply(paddedWin, padded1, padded1);
    multiply(paddedWin, padded2, padded2);
}

// execute phase correlation equation
// Reference: http://en.wikipedia.org/wiki/Phase_correlation
dft(padded1, FFT1, DFT_REAL_OUTPUT);
dft(padded2, FFT2, DFT_REAL_OUTPUT);

mulSpectrums(FFT1, FFT2, P, 0, true);

magSpectrums(P, Pm);
divSpectrums(P, Pm, C, 0, false); // FF* / |FF*| (phase correlation equation completed here...)

idft(C, C); // gives us the nice peak shift location...

fftShift(C); // shift the energy to the center of the frame.

// locate the highest peak
Point peakLoc;
minMaxLoc(C, NULL, NULL, NULL, &peakLoc);

// get the phase shift with sub-pixel accuracy, 5x5 window seems about right here...
Point2d t;
t = weightedCentroid(C, peakLoc, Size(5, 5), response);

// max response is M*N (not exactly, might be slightly larger due to rounding errors)
if(response)
    *response /= M*N;

// adjust shift relative to image center...
Point2d center((double)padded1.cols / 2.0, (double)padded1.rows / 2.0);

return (center - t);

}


after the dft(padded1, FFT1, DFT_REAL_OUTPUT) , I tried cvLogPolar ,but I can't get the right results as I try in MATLAB.

void cvLogPolar(const CvArr* src, CvArr* dst, CvPoint2D32f center, double M, int flags) (C function, in Geometric Image Transformations))

here is the Proposed Algorithm

(i) First two input images IR (x, y) and IS(x, y) (reference and sense) are loaded.

(ii) The approximate value of scale between the images is estimated, if there is a scale between the images then downscale the sense image by the factor of 2. After down scaling, apply zero padding to downscaled sense image IDS(x,y) to keep the size of both (reference and sense) images same.

(iii) 2D-FFT of both the images (reference ... (more)

edit retag flag offensive close merge delete