40 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_CATCH2)
45 #include <catch_amalgamated.hpp>
46 #include <visp3/core/vpImageTools.h>
48 static unsigned int g_input_width = 7;
49 static unsigned int g_input_height = 5;
50 static unsigned int g_output_width = 4;
51 static unsigned int g_output_height = 3;
53 #ifdef ENABLE_VISP_NAMESPACE
56 TEST_CASE(
"Nearest neighbor interpolation",
"[image_resize]")
58 SECTION(
"unsigned char")
61 common_tools::fill(I);
63 common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
68 std::cout <<
"I:\n" << I << std::endl;
69 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
70 std::cout <<
"Iresize:\n" << Iresize << std::endl;
72 CHECK((Iresize == Iresize_ref));
78 common_tools::fill(I);
80 common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
85 std::cout <<
"I:\n" << I << std::endl;
86 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
87 std::cout <<
"Iresize:\n" << Iresize << std::endl;
89 CHECK((Iresize == Iresize_ref));
93 TEST_CASE(
"Bilinear interpolation",
"[image_resize]")
95 SECTION(
"unsigned char")
98 common_tools::fill(I);
100 common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
105 std::cout <<
"I:\n" << I << std::endl;
106 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
107 std::cout <<
"Iresize:\n" << Iresize << std::endl;
109 CHECK((Iresize == Iresize_ref));
115 common_tools::fill(I);
117 common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
122 std::cout <<
"I:\n" << I << std::endl;
123 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
124 std::cout <<
"Iresize:\n" << Iresize << std::endl;
126 const double max_pixel_error = 0.5;
128 CHECK(common_tools::almostEqual(Iresize, Iresize_ref, max_pixel_error, error));
129 std::cout <<
"Error: " << error << std::endl;
133 int main(
int argc,
char *argv[])
135 Catch::Session session;
137 using namespace Catch::Clara;
138 auto cli = session.cli()
139 | Catch::Clara::Opt(g_input_width,
"g_input_width")[
"--iw"](
"Input image width.")
140 | Catch::Clara::Opt(g_input_height,
"g_input_height")[
"--ih"](
"Input image height.")
141 | Catch::Clara::Opt(g_output_width,
"g_output_width")[
"--ow"](
"Output image width.")
142 | Catch::Clara::Opt(g_output_height,
"g_output_height")[
"--oh"](
"Output image height.");
145 session.applyCommandLine(argc, argv);
147 std::cout <<
"Input image (wxh): " << g_input_width <<
"x" << g_input_height << std::endl;
148 std::cout <<
"Output image (wxh): " << g_output_width <<
"x" << g_output_height << std::endl;
150 int numFailed = session.run();
154 int main() {
return EXIT_SUCCESS; }