added the optional output maxima value to phaseCorrelate (patch #2071 by Robert Huitl)

This commit is contained in:
Vadim Pisarevsky 2012-06-22 13:34:03 +00:00
parent 511d09f587
commit 0c65ea976a
3 changed files with 16 additions and 5 deletions

View File

@ -151,11 +151,12 @@ The function is used to detect translational shifts that occur between two image
Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed with :ocv:func:`getOptimalDFTSize`.
.. ocv:function:: Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray())
.. ocv:function:: Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray(), double* response = 0)
:param src1: Source floating point array (CV_32FC1 or CV_64FC1)
:param src2: Source floating point array (CV_32FC1 or CV_64FC1)
:param window: Floating point array with windowing coefficients to reduce edge effects (optional).
:param response: Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional).
Return value: detected phase shift (sub-pixel) between the two arrays.
@ -190,6 +191,8 @@ The function performs the following equations
(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}
* If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5 centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single peak) and will be smaller when there are multiple peaks.
.. seealso::
:ocv:func:`dft`,
:ocv:func:`getOptimalDFTSize`,

View File

@ -600,7 +600,8 @@ CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
//! computes PSNR image/video quality metric
CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2);
CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray());
CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2,
InputArray window = noArray(), CV_OUT double* response=0);
CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);
//! type of the threshold operation

View File

@ -406,7 +406,7 @@ static void fftShift(InputOutputArray _out)
merge(planes, out);
}
static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize)
static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize, double* response)
{
Mat src = _src.getMat();
@ -475,6 +475,9 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz
}
}
if(response)
*response = sumIntensity;
sumIntensity += DBL_EPSILON; // prevent div0 problems...
centroid.x /= sumIntensity;
@ -485,7 +488,7 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz
}
cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window)
cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window, double* response)
{
Mat src1 = _src1.getMat();
Mat src2 = _src2.getMat();
@ -553,7 +556,11 @@ cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _w
// get the phase shift with sub-pixel accuracy, 5x5 window seems about right here...
Point2d t;
t = weightedCentroid(C, peakLoc, Size(5, 5));
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);