mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
imageXCorrDiscrete_test.cpp
Go to the documentation of this file.
1 /** \file imageXCorrDiscrete_test.cpp
2  */
3 #include "../../catch2/catch.hpp"
4 
5 #include <vector>
6 #include <Eigen/Dense>
7 
8 #define MX_NO_ERROR_REPORTS
9 
10 #include "../../../include/math/func/gaussian.hpp"
11 #include "../../../include/improc/imageXCorrDiscrete.hpp"
12 #include "../../../include/improc/eigenCube.hpp"
13 #include "../../../include/ioutils/fits/fitsFile.hpp"
14 
15 /** Scenario: centroiding Gaussians with center of light
16  *
17  * Verify center of light calculation
18  *
19  * \anchor tests_improc_imageUtils_imageXCorrDiscrete
20  */
21 SCENARIO( "Verify X-Corr with center of light calculation", "[improc::imageXCorrDiscrete]" )
22 {
23  GIVEN("two Gaussians")
24  {
25  WHEN("1 at geometric center")
26  {
28  im0.resize(64,64);
29  im2.resize(64,64);
30 
31  mx::math::func::gaussian2D<double>(im0.data(), im0.rows(), im0.cols(), 0., 1.0, 31.5, 31.5, 2);
32  mx::math::func::gaussian2D<double>(im2.data(), im2.rows(), im2.cols(), 0., 1.0, 31.5+4, 31.5+4, 2);
33 
34  double x, y;
36 
37  mx::improc::eigenImage<double> refIm = im0.block(10,10, im0.rows()-11, im0.cols()-11);
38  xcf.refIm(refIm);
39  xcf.m_peakMethod = mx::improc::xcorrPeakMethod::centroid;
40 
41 
42  xcf(x, y, im2);
43 
45  ff.write("refIm.fits", xcf.m_refIm);
46  ff.write("ccIm.fits", xcf.m_ccIm);
47 
48  std::cerr << x << " " << y << "\n";
49 
50  REQUIRE(fabs(x-2) < 1e-8 );
51  REQUIRE(fabs(y-2) < 1e-8 );
52  }
53  WHEN("geometric quarter")
54  {
56  im.resize(64,64);
57 
58  mx::math::func::gaussian2D<double>(im.data(), im.rows(), im.cols(), 0., 1.0, 15.5, 15.5, 2);
59 
60  double x, y;
62 
63  REQUIRE(fabs(x-15.5) < 1e-8 );
64  REQUIRE(fabs(y-15.5) < 1e-8 );
65  }
66  }
67 }
68 
69 
70 
Class to manage interactions with a FITS file.
Definition: fitsFile.hpp:54
int write(const dataT *im, int d1, int d2, int d3, fitsHeader *head)
Write the contents of a raw array to the FITS file.
Definition: fitsFile.hpp:1301
Find the optimum shift to align two images using the discrete cross correlation.
ccImT m_ccIm
The cross-correlation image.
ccImT m_refIm
The normalized reference image.
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.
Definition: eigenImage.hpp:44
int imageCenterOfLight(typename imageT::Scalar &x, typename imageT::Scalar &y, const imageT &im)
Calculate the center of light of an image.
Definition: imageUtils.hpp:163
SCENARIO("Verify X-Corr with center of light calculation", "[improc::imageXCorrDiscrete]")