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"
13 #include "../../../include/ioutils/fits/fitsFile.hpp"
21 SCENARIO(
"Image cross-correlation with FFT using center of light",
"[improc::imageXCorrFFT]" )
23 GIVEN(
"two Gaussians")
25 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)")
36 double xcen = 0.5*(im0.rows()-1);
37 double ycen = 0.5*(im0.cols()-1);
39 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
40 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
46 xcf.peakMethod(mx::improc::xcorrPeakMethod::centerOfLight);
55 REQUIRE(x == Approx(xshift) );
56 REQUIRE(y == Approx(yshift) );
58 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)")
69 double xcen = 0.5*(im0.rows()-1);
70 double ycen = 0.5*(im0.cols()-1);
72 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
73 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
80 xcf.peakMethod(mx::improc::xcorrPeakMethod::centerOfLight);
88 REQUIRE(x == Approx(xshift) );
89 REQUIRE(y == Approx(yshift) );
91 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)")
102 double xcen = 0.5*(im0.rows()-1);
103 double ycen = 0.5*(im0.cols()-1);
105 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
106 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
113 xcf.peakMethod(mx::improc::xcorrPeakMethod::centerOfLight);
121 REQUIRE(x == Approx(xshift) );
122 REQUIRE(y == Approx(yshift) );
124 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)")
127 double yshift = -0.6;
135 double xcen = 0.5*(im0.rows()-1);
136 double ycen = 0.5*(im0.cols()-1);
138 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
139 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
146 xcf.peakMethod(mx::improc::xcorrPeakMethod::centerOfLight);
154 REQUIRE(x == Approx(xshift) );
155 REQUIRE(y == Approx(yshift) );
166 SCENARIO(
"Image cross-correlation with FFT using magnification peak finding",
"[improc::imageXCorrFFT]" )
168 GIVEN(
"two Gaussians")
170 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)")
181 double xcen = 0.5*(im0.rows()-1);
182 double ycen = 0.5*(im0.cols()-1);
184 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
185 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
191 xcf.peakMethod(mx::improc::xcorrPeakMethod::interpPeak);
200 REQUIRE(x == Approx(xshift) );
201 REQUIRE(y == Approx(yshift) );
204 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)")
215 double xcen = 0.5*(im0.rows()-1);
216 double ycen = 0.5*(im0.cols()-1);
218 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
219 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
226 xcf.peakMethod(mx::improc::xcorrPeakMethod::interpPeak);
236 REQUIRE(x == Approx(xshift) );
237 REQUIRE(y == Approx(yshift) );
239 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.3)")
241 double xshift = -3.6;
250 double xcen = 0.5*(im0.rows()-1);
251 double ycen = 0.5*(im0.cols()-1);
253 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
254 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
261 xcf.peakMethod(mx::improc::xcorrPeakMethod::interpPeak);
269 REQUIRE(x == Approx(xshift) );
270 REQUIRE(y == Approx(yshift) );
272 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)")
275 double yshift = -0.6;
283 double xcen = 0.5*(im0.rows()-1);
284 double ycen = 0.5*(im0.cols()-1);
286 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
287 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
294 xcf.peakMethod(mx::improc::xcorrPeakMethod::interpPeak);
302 REQUIRE(x == Approx(xshift) );
303 REQUIRE(y == Approx(yshift) );
309 SCENARIO(
"Image cross-correlation with FFT using Gaussian peak fit",
"[improc::imageXCorrFFT]" )
311 GIVEN(
"two Gaussians")
313 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)")
324 double xcen = 0.5*(im0.rows()-1);
325 double ycen = 0.5*(im0.cols()-1);
327 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
328 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
334 xcf.peakMethod(mx::improc::xcorrPeakMethod::gaussFit);
343 REQUIRE(x == Approx(xshift) );
344 REQUIRE(y == Approx(yshift) );
346 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)")
357 double xcen = 0.5*(im0.rows()-1);
358 double ycen = 0.5*(im0.cols()-1);
360 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
361 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
368 xcf.peakMethod(mx::improc::xcorrPeakMethod::gaussFit);
376 REQUIRE(x == Approx(xshift) );
377 REQUIRE(y == Approx(yshift) );
379 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)")
381 double xshift = -3.6;
382 double yshift = 2.25;
390 double xcen = 0.5*(im0.rows()-1);
391 double ycen = 0.5*(im0.cols()-1);
393 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
394 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
400 xcf.peakMethod(mx::improc::xcorrPeakMethod::gaussFit);
410 REQUIRE(x == Approx(xshift) );
411 REQUIRE(y == Approx(yshift) );
413 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)")
416 double yshift = -0.6;
424 double xcen = 0.5*(im0.rows()-1);
425 double ycen = 0.5*(im0.cols()-1);
427 mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2);
428 mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen+xshift, ycen+yshift, 2);
435 xcf.peakMethod(mx::improc::xcorrPeakMethod::gaussFit);
443 REQUIRE(x == Approx(xshift) );
444 REQUIRE(y == Approx(yshift) );
Class to manage interactions with a FITS file.
int write(const dataT *im, int d1, int d2, int d3, fitsHeader *head)
Write the contents of a raw array to the FITS file.
Find the optimum shift to align two images using the FFT cross correlation.
const ccImT & ccIm()
Get a reference to the cross correlation image.
int maxLag()
Get the current maximum lag.
Scalar tol()
Get the tolerance of the interpolated-magnified image, in pixels.
int refIm(const ccImT &im0)
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]")