mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
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
17namespace
18{
19double imageMSE( const mx::improc::eigenImage<double> &a, const mx::improc::eigenImage<double> &b )
20{
21 return ( a - b ).square().mean();
22}
23} // namespace
24
25/** Scenario: Verify direction and accuracy of various image shifts
26 *
27 * Tests image shifts by fractional pixels.
28 *
29 * \anchor tests_improc_imageTransforms_imageShift
30 */
31SCENARIO( "Verify direction and accuracy of various image shifts", "[improc::imageTransforms]" )
32{
33 GIVEN( "a Gaussian image" )
34 {
35 WHEN( "shifting" )
36 {
37 mx::improc::eigenImage<double> im, shift, ref;
38
39 im.resize( 256, 256 );
40 shift.resize( im.rows(), im.cols() );
41 ref.resize( im.rows(), im.cols() );
42
43 // Use sigma = 8 to get a well oversampled image, making shifts more accurate
44 mx::math::func::gaussian2D<double>( im.data(), im.rows(), im.cols(), 0., 1.0, 127.5, 127.5, 8 );
45
47 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 127.0, 127.0, 8 );
48 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
49
51 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 128.0, 128.0, 8 );
52 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
53
55 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 128.5, 128.5, 8 );
56 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
57
59 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 128.0, 127.0, 8 );
60 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
61
63 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 127.2, 128.2, 8 );
64 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
65
67 mx::math::func::gaussian2D<double>( ref.data(), ref.rows(), ref.cols(), 0., 1.0, 128.8, 126.8, 8 );
68 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
69 }
70 }
71}
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
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.