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"
21SCENARIO(
"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)" )
33 im0.resize( xsz, ysz );
34 im2.resize( xsz, ysz );
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>(
41 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
47 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
56 REQUIRE( x == Approx( xshift ) );
57 REQUIRE( y == Approx( yshift ) );
59 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
67 im0.resize( xsz, ysz );
68 im2.resize( xsz, ysz );
70 double xcen = 0.5 * ( im0.rows() - 1 );
71 double ycen = 0.5 * ( im0.cols() - 1 );
73 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
74 mx::math::func::gaussian2D<double>(
75 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
82 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
90 REQUIRE( x == Approx( xshift ) );
91 REQUIRE( y == Approx( yshift ) );
93 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)" )
101 im0.resize( xsz, ysz );
102 im2.resize( xsz, ysz );
104 double xcen = 0.5 * ( im0.rows() - 1 );
105 double ycen = 0.5 * ( im0.cols() - 1 );
107 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
108 mx::math::func::gaussian2D<double>(
109 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
116 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
124 REQUIRE( x == Approx( xshift ) );
125 REQUIRE( y == Approx( yshift ) );
127 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
130 double yshift = -0.6;
135 im0.resize( xsz, ysz );
136 im2.resize( xsz, ysz );
138 double xcen = 0.5 * ( im0.rows() - 1 );
139 double ycen = 0.5 * ( im0.cols() - 1 );
141 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
142 mx::math::func::gaussian2D<double>(
143 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
150 xcf.peakMethod( mx::improc::xcorrPeakMethod::centerOfLight );
158 REQUIRE( x == Approx( xshift ) );
159 REQUIRE( y == Approx( yshift ) );
170SCENARIO(
"Image cross-correlation with FFT using magnification peak finding",
"[improc::imageXCorrFFT]" )
172 GIVEN(
"two Gaussians" )
174 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)" )
182 im0.resize( xsz, ysz );
183 im2.resize( xsz, ysz );
185 double xcen = 0.5 * ( im0.rows() - 1 );
186 double ycen = 0.5 * ( im0.cols() - 1 );
188 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
189 mx::math::func::gaussian2D<double>(
190 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
196 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
205 REQUIRE( x == Approx( xshift ) );
206 REQUIRE( y == Approx( yshift ) );
208 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
216 im0.resize( xsz, ysz );
217 im2.resize( xsz, ysz );
219 double xcen = 0.5 * ( im0.rows() - 1 );
220 double ycen = 0.5 * ( im0.cols() - 1 );
222 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
223 mx::math::func::gaussian2D<double>(
224 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
231 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
241 REQUIRE( x == Approx( xshift ) );
242 REQUIRE( y == Approx( yshift ) );
244 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.3)" )
246 double xshift = -3.6;
252 im0.resize( xsz, ysz );
253 im2.resize( xsz, ysz );
255 double xcen = 0.5 * ( im0.rows() - 1 );
256 double ycen = 0.5 * ( im0.cols() - 1 );
258 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
259 mx::math::func::gaussian2D<double>(
260 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
267 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
275 REQUIRE( x == Approx( xshift ) );
276 REQUIRE( y == Approx( yshift ) );
278 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
281 double yshift = -0.6;
286 im0.resize( xsz, ysz );
287 im2.resize( xsz, ysz );
289 double xcen = 0.5 * ( im0.rows() - 1 );
290 double ycen = 0.5 * ( im0.cols() - 1 );
292 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
293 mx::math::func::gaussian2D<double>(
294 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
301 xcf.peakMethod( mx::improc::xcorrPeakMethod::interpPeak );
309 REQUIRE( x == Approx( xshift ) );
310 REQUIRE( y == Approx( yshift ) );
315SCENARIO(
"Image cross-correlation with FFT using Gaussian peak fit",
"[improc::imageXCorrFFT]" )
317 GIVEN(
"two Gaussians" )
319 WHEN(
"ref at geometric center, equal even sizes, shift=(+4,+4)" )
327 im0.resize( xsz, ysz );
328 im2.resize( xsz, ysz );
330 double xcen = 0.5 * ( im0.rows() - 1 );
331 double ycen = 0.5 * ( im0.cols() - 1 );
333 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
334 mx::math::func::gaussian2D<double>(
335 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
341 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
350 REQUIRE( x == Approx( xshift ) );
351 REQUIRE( y == Approx( yshift ) );
353 WHEN(
"ref at geometric center, equal odd sizes, shift=(+4,+4)" )
361 im0.resize( xsz, ysz );
362 im2.resize( xsz, ysz );
364 double xcen = 0.5 * ( im0.rows() - 1 );
365 double ycen = 0.5 * ( im0.cols() - 1 );
367 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
368 mx::math::func::gaussian2D<double>(
369 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
376 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
384 REQUIRE( x == Approx( xshift ) );
385 REQUIRE( y == Approx( yshift ) );
387 WHEN(
"ref at geometric center, equal even sizes, shift=(-3.6,+2.25)" )
389 double xshift = -3.6;
390 double yshift = 2.25;
395 im0.resize( xsz, ysz );
396 im2.resize( xsz, ysz );
398 double xcen = 0.5 * ( im0.rows() - 1 );
399 double ycen = 0.5 * ( im0.cols() - 1 );
401 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
402 mx::math::func::gaussian2D<double>(
403 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
409 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
419 REQUIRE( x == Approx( xshift ) );
420 REQUIRE( y == Approx( yshift ) );
422 WHEN(
"ref at geometric center, equal odd sizes, shift=(+1.3,-0.6)" )
425 double yshift = -0.6;
430 im0.resize( xsz, ysz );
431 im2.resize( xsz, ysz );
433 double xcen = 0.5 * ( im0.rows() - 1 );
434 double ycen = 0.5 * ( im0.cols() - 1 );
436 mx::math::func::gaussian2D<double>( im0.data(), im0.rows(), im0.cols(), 0., 1.0, xcen, ycen, 2 );
437 mx::math::func::gaussian2D<double>(
438 im2.data(), im2.rows(), im2.cols(), 0., 1.0, xcen + xshift, ycen + yshift, 2 );
445 xcf.peakMethod( mx::improc::xcorrPeakMethod::gaussFit );
453 REQUIRE( x == Approx( xshift ) );
454 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.
void maxLag(int ml)
Set the maximum lag.
void tol(realT nt)
Set the tolerance of the interpolated-magnified image, in pixels.
const realImageT & ccIm()
Get a reference to the cross correlation image.
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]")