44TEST_CASE(
"Verify direction and accuracy of various image shifts",
"[improc::imageTransforms]" )
46 GIVEN(
"a Gaussian image" )
52 im.resize( 256, 256 );
53 shift.resize( im.rows(), im.cols() );
54 ref.resize( im.rows(), im.cols() );
61 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
65 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
69 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
73 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
77 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
81 REQUIRE_THAT( imageMSE( shift, ref ), Catch::Matchers::WithinAbs( 0.0, 1e-5 ) );
90TEST_CASE(
"cubicConvolTransform produces normalized four-pixel kernels",
91 "[improc::cubicConvolTransform][improc::imageTransforms]" )
94 constexpr Eigen::Index transformWidth = transformT::width;
95 constexpr Eigen::Index leftBuffer = transformT::lbuff;
99 REQUIRE( transform.cubic == -0.5F );
100 REQUIRE( transformWidth == 4 );
101 REQUIRE( leftBuffer == 1 );
103 REQUIRE( transform.cubicConvolKernel( 0.0F ) == 1.0F );
104 REQUIRE( transform.cubicConvolKernel( 0.25F ) == 0.8671875F );
105 REQUIRE( transform.cubicConvolKernel( 0.5F ) == 0.5625F );
106 REQUIRE( transform.cubicConvolKernel( 0.75F ) == 0.2265625F );
107 REQUIRE( transform.cubicConvolKernel( 1.0F ) == 0.0F );
108 REQUIRE( transform.cubicConvolKernel( 1.25F ) == -0.0703125F );
109 REQUIRE( transform.cubicConvolKernel( 1.5F ) == -0.0625F );
110 REQUIRE( transform.cubicConvolKernel( 1.75F ) == -0.0234375F );
111 REQUIRE( transform.cubicConvolKernel( 2.0F ) == 0.0F );
113 const std::array<std::array<float, 2>, 4> phases{
114 { { 0.0F, 0.0F }, { 0.25F, 0.75F }, { 0.5F, 0.5F }, { 0.75F, 0.25F } } };
117 for(
const auto &phase : phases )
119 transform( kernel, phase[0], phase[1] );
120 REQUIRE( kernel.sum() == 1.0F );
123 const std::array<float, 4> quarterWeights{ -0.0703125F, 0.8671875F, 0.2265625F, -0.0234375F };
124 const std::array<float, 4> threeQuarterWeights{ -0.0234375F, 0.2265625F, 0.8671875F, -0.0703125F };
126 transform( kernel, 0.25F, 0.75F );
127 for( Eigen::Index row = 0; row < kernel.rows(); ++row )
129 for( Eigen::Index col = 0; col < kernel.cols(); ++col )
131 REQUIRE( kernel( row, col ) == quarterWeights[row] * threeQuarterWeights[col] );
136 const Eigen::Index firstAnchor = leftBuffer;
137 const Eigen::Index lastAnchor = constantImage.rows() - transformWidth + leftBuffer;
138 const std::array<Eigen::Index, 2> anchors{ firstAnchor, lastAnchor };
140 REQUIRE( firstAnchor - leftBuffer == 0 );
141 REQUIRE( lastAnchor - leftBuffer + transformWidth == constantImage.rows() );
142 REQUIRE( firstAnchor - 1 - leftBuffer < 0 );
143 REQUIRE( lastAnchor + 1 - leftBuffer + transformWidth > constantImage.rows() );
145 for( Eigen::Index rowAnchor : anchors )
147 for( Eigen::Index colAnchor : anchors )
149 transform( kernel, 0.25F, 0.75F );
150 const float sample = ( constantImage.block( rowAnchor - leftBuffer,
151 colAnchor - leftBuffer,
156 REQUIRE( sample == 3.25F );
realT gaussian2D(const realT x, const realT y, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma)
Find value at position (x,y) of the 2D arbitrarily-centered symmetric Gaussian.