42 #include <visp3/core/vpConfig.h> 44 #if defined(VISP_HAVE_CATCH2) 45 #define CATCH_CONFIG_RUNNER 47 #include <visp3/core/vpImageTools.h> 50 static unsigned int g_input_width = 7;
51 static unsigned int g_input_height = 5;
52 static unsigned int g_output_width = 4;
53 static unsigned int g_output_height = 3;
55 TEST_CASE(
"Nearest neighbor interpolation",
"[image_resize]") {
56 SECTION(
"unsigned char")
59 common_tools::fill(I);
61 common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
66 std::cout <<
"I:\n" << I << std::endl;
67 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
68 std::cout <<
"Iresize:\n" << Iresize << std::endl;
70 CHECK((Iresize == Iresize_ref));
76 common_tools::fill(I);
78 common_tools::resizeRef(I, Iresize_ref, common_tools::g_nearest_neighbor);
83 std::cout <<
"I:\n" << I << std::endl;
84 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
85 std::cout <<
"Iresize:\n" << Iresize << std::endl;
87 CHECK((Iresize == Iresize_ref));
91 TEST_CASE(
"Bilinear interpolation",
"[image_resize]") {
92 SECTION(
"unsigned char")
95 common_tools::fill(I);
97 common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
102 std::cout <<
"I:\n" << I << std::endl;
103 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
104 std::cout <<
"Iresize:\n" << Iresize << std::endl;
106 CHECK((Iresize == Iresize_ref));
112 common_tools::fill(I);
114 common_tools::resizeRef(I, Iresize_ref, common_tools::g_bilinear);
119 std::cout <<
"I:\n" << I << std::endl;
120 std::cout <<
"Iresize_ref:\n" << Iresize_ref << std::endl;
121 std::cout <<
"Iresize:\n" << Iresize << std::endl;
123 const double max_pixel_error = 0.5;
125 CHECK(common_tools::almostEqual(Iresize, Iresize_ref, max_pixel_error, error));
126 std::cout <<
"Error: " << error << std::endl;
130 int main(
int argc,
char *argv[])
132 Catch::Session session;
135 using namespace Catch::clara;
136 auto cli = session.cli()
137 | Opt(g_input_width,
"g_input_width")
139 (
"Input image width.")
140 | Opt(g_input_height,
"g_input_height")
142 (
"Input image height.")
143 | Opt(g_output_width,
"g_output_width")
145 (
"Output image width.")
146 | Opt(g_output_height,
"g_output_height")
148 (
"Output image height.");
154 session.applyCommandLine(argc, argv);
156 std::cout <<
"Input image (wxh): " << g_input_width <<
"x" << g_input_height << std::endl;
157 std::cout <<
"Output image (wxh): " << g_output_width <<
"x" << g_output_height << std::endl;
159 int numFailed = session.run();