mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
imageTransforms_test.cpp
Go to the documentation of this file.
1 /** \file imageTransforms_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 
12 #include "../../../include/improc/imageUtils.hpp"
13 #include "../../../include/improc/eigenCube.hpp"
14 
15 #include "../../../include/improc/imageTransforms.hpp"
16 
17 #include "../../../include/math/fit/fitGaussian.hpp"
18 
19 /** Scenario: Verify direction and accuracy of various image shifts
20  *
21  * Tests image shifts by fractional pixels.
22  *
23  * \anchor tests_improc_imageTransforms_imageShift
24  */
25 SCENARIO( "Verify direction and accuracy of various image shifts", "[improc::imageTransforms]" )
26 {
27  GIVEN("a Gaussian image")
28  {
29  WHEN("shifting")
30  {
33  double x, y;
34 
35  im.resize(256,256);
36  shift.resize(im.rows(), im.cols());
37 
38  fit.setArray(shift.data(), shift.rows(), shift.cols());
39 
40  //Use sigma = 8 to get a well oversampled image, making shifts more accurate
41  mx::math::func::gaussian2D<double>(im.data(), im.rows(), im.cols(), 0., 1.0, 127.5, 127.5, 8);
42  fit.setGuess(0.0, 1.0, 127.5, 127.5, 8.0);
43 
45  fit.fit();
46  REQUIRE(fabs(fit.x0() - 127.0) < 1e-4);//should be much better than this, but this is a test
47  REQUIRE(fabs(fit.y0() - 127.0) < 1e-4);
48 
50  fit.fit();
51  REQUIRE(fabs(fit.x0() - 128.0) < 1e-4);
52  REQUIRE(fabs(fit.y0() - 128.0) < 1e-4);
53 
55  fit.fit();
56  REQUIRE(fabs(fit.x0() - 128.5) < 1e-4);
57  REQUIRE(fabs(fit.y0() - 128.5) < 1e-4);
58 
59 
61  fit.fit();
62  REQUIRE(fabs(fit.x0() - 128.0) < 1e-4);
63  REQUIRE(fabs(fit.y0() - 127.0) < 1e-4);
64 
66  fit.fit();
67  REQUIRE(fabs(fit.x0() - 127.2) < 1e-3); //non-0.5 pixel shifts are harder
68  REQUIRE(fabs(fit.y0() - 128.2) < 1e-3);
69 
71  fit.fit();
72  REQUIRE(fabs(fit.x0() - 128.8) < 1e-3);
73  REQUIRE(fabs(fit.y0() - 126.8) < 1e-3);
74  }
75  }
76 }
77 
78 
79 
Class to manage fitting a 2D Gaussian to data via the levmarInterface.
realT x0()
Get the center x-coordinate.
void setGuess(realT G0, realT G, realT x0, realT y0, realT sigma)
Set the initial guess for a symmetric Gaussian.
realT y0()
Get the center y-coordinate.
void setArray(realT *data, int nx, int ny)
Set the data aray.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
Definition: eigenImage.hpp:44
void imageShift(arrOutT &transim, const arrInT &im, floatT1 dx, floatT2 dy, transformT trans)
Shift an image.
SCENARIO("Verify direction and accuracy of various image shifts", "[improc::imageTransforms]")
Transformation by cubic convolution interpolation.