3#include "../../catch2/catch.hpp"
8#define MX_NO_ERROR_REPORTS
10#include "../../../include/math/func/gaussian.hpp"
11#include "../../../include/improc/imageXCorrFFT.hpp"
12#include "../../../include/improc/eigenCube.hpp"
20SCENARIO(
"Image cross-correlation with FFT using center of light",
"[improc::imageXCorrFFT]" )
22 GIVEN(
"two Gaussians" )
24 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)" )
32 im0.resize( xsz, ysz );
33 im2.resize( xsz, ysz );
35 double xcen = 0.5 * ( im0.rows() - 1 );
36 double ycen = 0.5 * ( im0.cols() - 1 );
38 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
39 mx::math::func::gaussian2D<double>( im2.data(),
52 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
55 xcf( x, y, peak, im2 );
57 REQUIRE( x == Approx( xshift ) );
58 REQUIRE( y == Approx( yshift ) );
61 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
69 im0.resize( xsz, ysz );
70 im2.resize( xsz, ysz );
72 double xcen = 0.5 * ( im0.rows() - 1 );
73 double ycen = 0.5 * ( im0.cols() - 1 );
75 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
77 mx::math::func::gaussian2D<double>( im2.data(),
88 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
94 xcf( x, y, peak, im2 );
96 REQUIRE( x == Approx( xshift ) );
97 REQUIRE( y == Approx( yshift ) );
100 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)" )
102 double xshift = -3.6;
103 double yshift = 2.25;
108 im0.resize( xsz, ysz );
109 im2.resize( xsz, ysz );
111 double xcen = 0.5 * ( im0.rows() - 1 );
112 double ycen = 0.5 * ( im0.cols() - 1 );
114 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
115 mx::math::func::gaussian2D<double>( im2.data(),
126 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
132 xcf( x, y, peak, im2 );
134 REQUIRE( x == Approx( xshift ) );
135 REQUIRE( y == Approx( yshift ) );
138 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
141 double yshift = -0.6;
146 im0.resize( xsz, ysz );
147 im2.resize( xsz, ysz );
149 double xcen = 0.5 * ( im0.rows() - 1 );
150 double ycen = 0.5 * ( im0.cols() - 1 );
152 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
153 mx::math::func::gaussian2D<double>( im2.data(),
164 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
170 xcf( x, y, peak, im2 );
172 REQUIRE( x == Approx( xshift ) );
173 REQUIRE( y == Approx( yshift ) );
185SCENARIO(
"Image cross-correlation with FFT using magnification peak finding",
"[improc::imageXCorrFFT]" )
187 GIVEN(
"two Gaussians" )
189 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)" )
197 im0.resize( xsz, ysz );
198 im2.resize( xsz, ysz );
200 double xcen = 0.5 * ( im0.rows() - 1 );
201 double ycen = 0.5 * ( im0.cols() - 1 );
203 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
204 mx::math::func::gaussian2D<double>( im2.data(),
215 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
221 xcf( x, y, peak, im2 );
223 REQUIRE( x == Approx( xshift ) );
224 REQUIRE( y == Approx( yshift ) );
227 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
235 im0.resize( xsz, ysz );
236 im2.resize( xsz, ysz );
238 double xcen = 0.5 * ( im0.rows() - 1 );
239 double ycen = 0.5 * ( im0.cols() - 1 );
241 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
242 mx::math::func::gaussian2D<double>( im2.data(),
256 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
260 xcf( x, y, peak, im2 );
262 REQUIRE( x == Approx( xshift ) );
263 REQUIRE( y == Approx( yshift ) );
266 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.3)" )
268 double xshift = -3.6;
274 im0.resize( xsz, ysz );
275 im2.resize( xsz, ysz );
277 double xcen = 0.5 * ( im0.rows() - 1 );
278 double ycen = 0.5 * ( im0.cols() - 1 );
280 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
281 mx::math::func::gaussian2D<double>( im2.data(),
292 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
298 xcf( x, y, peak, im2 );
300 REQUIRE( x == Approx( xshift ) );
301 REQUIRE( y == Approx( yshift ) );
304 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
307 double yshift = -0.6;
312 im0.resize( xsz, ysz );
313 im2.resize( xsz, ysz );
315 double xcen = 0.5 * ( im0.rows() - 1 );
316 double ycen = 0.5 * ( im0.cols() - 1 );
318 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
319 mx::math::func::gaussian2D<double>( im2.data(),
330 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
336 xcf( x, y, peak, im2 );
338 REQUIRE( x == Approx( xshift ) );
339 REQUIRE( y == Approx( yshift ) );
345SCENARIO(
"Image cross-correlation with FFT using Gaussian peak fit",
"[improc::imageXCorrFFT]" )
347 GIVEN(
"two Gaussians" )
349 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)" )
357 im0.resize( xsz, ysz );
358 im2.resize( xsz, ysz );
360 double xcen = 0.5 * ( im0.rows() - 1 );
361 double ycen = 0.5 * ( im0.cols() - 1 );
363 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
364 mx::math::func::gaussian2D<double>( im2.data(),
377 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
380 xcf( x, y, peak, im2 );
382 REQUIRE( x == Approx( xshift ) );
383 REQUIRE( y == Approx( yshift ) );
386 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
394 im0.resize( xsz, ysz );
395 im2.resize( xsz, ysz );
397 double xcen = 0.5 * ( im0.rows() - 1 );
398 double ycen = 0.5 * ( im0.cols() - 1 );
400 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
401 mx::math::func::gaussian2D<double>( im2.data(),
412 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
418 xcf( x, y, peak, im2 );
420 REQUIRE( x == Approx( xshift ) );
421 REQUIRE( y == Approx( yshift ) );
424 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)" )
426 double xshift = -3.6;
427 double yshift = 2.25;
432 im0.resize( xsz, ysz );
433 im2.resize( xsz, ysz );
435 double xcen = 0.5 * ( im0.rows() - 1 );
436 double ycen = 0.5 * ( im0.cols() - 1 );
438 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
439 mx::math::func::gaussian2D<double>( im2.data(),
452 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
456 xcf( x, y, peak, im2 );
458 REQUIRE( x == Approx( xshift ) );
459 REQUIRE( y == Approx( yshift ) );
462 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
465 double yshift = -0.6;
470 im0.resize( xsz, ysz );
471 im2.resize( xsz, ysz );
473 double xcen = 0.5 * ( im0.rows() - 1 );
474 double ycen = 0.5 * ( im0.cols() - 1 );
476 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
477 mx::math::func::gaussian2D<double>( im2.data(),
488 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
494 xcf( x, y, peak, im2 );
496 REQUIRE( x == Approx( xshift ) );
497 REQUIRE( y == Approx( yshift ) );
Find the optimum shift to align two images using the FFT cross correlation.
void maxLag(int ml)
Set the maximum lag.
void tol(realT nt)
Set the tolerance of the interpolated-magnified image, in pixels.
int refIm(const realImageT &im0, realT padFactor)
Set the reference image.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
SCENARIO("Image cross-correlation with FFT using center of light", "[improc::imageXCorrFFT]")