Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
meshtag committed Jun 6, 2021
1 parent 91e052b commit 060b66c
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 45 deletions.
68 changes: 47 additions & 21 deletions test/extension/numeric/convolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,56 @@ struct test_image_5x5_kernel_1x9_boundary_extend_reflection
using channel_t = typename gil::channel_type<pixel_t>::type;
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
auto img_view = gil::view(img);
image_t img_out(img), img_expected_row(img);
unsigned int kernel_shift_offset = 2;

fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row),
kernel_shift_offset);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row),
image_t img_out_up_left_offset(img), img_expected_row_up_offset(img);
image_t img_expected_col_left_offset(img), img_out_down_right_offset(img);
image_t img_expected_row_down_offset(img), img_expected_col_right_offset(img);
int kernel_shift_up_left_offset = 2, kernel_shift_down_right_offset = -2;

fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset),
kernel_shift_up_left_offset);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset),
-1, 0, 1, img_view.height(), 1);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row),
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset),
1, 0, 0, img_view.height(), 2);

image_t img_expected_col(img);

fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row),
gil::view(img_expected_col), kernel_shift_offset);
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row),
gil::view(img_expected_col), -1, 1, 0, 1, img_view.width());
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row),
gil::view(img_expected_col), 1, 0, 0, 2, img_view.width());

auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::detail::convolve_1d<pixel_t>(gil::const_view(img), kernel, gil::view(img_out),
gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected_col)));
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset),
gil::view(img_expected_col_left_offset), kernel_shift_up_left_offset);
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset),
gil::view(img_expected_col_left_offset), -1, 1, 0, 1, img_view.width());
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset),
gil::view(img_expected_col_left_offset), 1, 0, 0, 2, img_view.width());

fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset),
kernel_shift_down_right_offset, 0, 2, img_view.height(), img_view.width());
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset),
-1, 0, img_view.width() - 1, img_view.height(), img_view.width());
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset),
1, 0, img_view.width() - 2, img_view.height(), img_view.width());

fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset),
gil::view(img_expected_col_right_offset), kernel_shift_down_right_offset, 2, 0,
img_view.height(), img_view.width());
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset),
gil::view(img_expected_col_right_offset), -1, img_view.height() - 1, 0,
img_view.height(), img_view.width());
fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset),
gil::view(img_expected_col_right_offset), 1, img_view.height() - 2, 0,
img_view.height(), img_view.width());

auto const kernel_up_left_offset = fixture::create_kernel<channel_t>(
{0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::detail::convolve_1d<pixel_t>(gil::const_view(img), kernel_up_left_offset,
gil::view(img_out_up_left_offset), gil::boundary_option::extend_reflection);

auto const kernel_down_right_offset = fixture::create_kernel<channel_t>(
{0, 0, 1, 0, 0, 0, 0, 0, 0});
gil::detail::convolve_1d<pixel_t>(gil::const_view(img), kernel_down_right_offset,
gil::view(img_out_down_right_offset), gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_up_left_offset),
gil::const_view(img_expected_col_left_offset)));
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_down_right_offset),
gil::const_view(img_expected_col_right_offset)));
}
static void run()
{
Expand Down
39 changes: 28 additions & 11 deletions test/extension/numeric/convolve_cols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,38 @@ struct test_image_5x5_kernel_1x9_boundary_extend_reflection
using channel_t = typename gil::channel_type<pixel_t>::type;
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
auto img_view = gil::view(img);
image_t img_out(img), img_expected(img);
unsigned int kernel_shift_offset = 2;
image_t img_out_left_offset(img), img_expected_left_offset(img);
image_t img_out_right_offset(img), img_expected_right_offset(img);
int kernel_shift_left_offset = 2, kernel_shift_right_offset = -2;

fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected),
kernel_shift_offset);
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected),
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_left_offset),
kernel_shift_left_offset);
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_left_offset),
-1, 1, 0, 1, img_view.width());
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected),
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_left_offset),
1, 0, 0, 2, img_view.width());

auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::convolve_cols<pixel_t>(gil::const_view(img), kernel, gil::view(img_out),
gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_right_offset),
kernel_shift_right_offset, 2, 0, img_view.height(), img_view.width());
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_right_offset),
-1, img_view.height() - 1, 0, img_view.height(), img_view.width());
fixture::col_conv1D_offset_img_generator(img_view, gil::view(img_expected_right_offset),
1, img_view.height() - 2, 0, img_view.height(), img_view.width());

auto const kernel_left_offset = fixture::create_kernel<channel_t>(
{0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::convolve_cols<pixel_t>(gil::const_view(img), kernel_left_offset,
gil::view(img_out_left_offset), gil::boundary_option::extend_reflection);

auto const kernel_right_offset = fixture::create_kernel<channel_t>(
{0, 0, 1, 0, 0, 0, 0, 0, 0});
gil::convolve_cols<pixel_t>(gil::const_view(img), kernel_right_offset,
gil::view(img_out_right_offset), gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_left_offset),
gil::const_view(img_expected_left_offset)));
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_right_offset),
gil::const_view(img_expected_right_offset)));
}
static void run()
{
Expand Down
39 changes: 28 additions & 11 deletions test/extension/numeric/convolve_rows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,38 @@ struct test_image_5x5_kernel_1x9_boundary_extend_reflection
using channel_t = typename gil::channel_type<pixel_t>::type;
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
auto img_view = gil::view(img);
image_t img_out(img), img_expected(img);
unsigned int kernel_shift_offset = 2;
image_t img_out_up_offset(img), img_expected_up_offset(img);
image_t img_out_down_offset(img), img_expected_down_offset(img);
int kernel_shift_up_offset = 2, kernel_shift_down_offset = -2;

fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected),
kernel_shift_offset);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected),
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_up_offset),
kernel_shift_up_offset);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_up_offset),
-1, 0, 1, img_view.height(), 1);
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected),
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_up_offset),
1, 0, 0, img_view.height(), 2);

auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::convolve_rows<pixel_t>(gil::const_view(img), kernel, gil::view(img_out),
gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_down_offset),
kernel_shift_down_offset, 0, 2, img_view.height(), img_view.width());
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_down_offset),
-1, 0, img_view.width() - 1, img_view.height(), img_view.width());
fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_down_offset),
1, 0, img_view.width() - 2, img_view.height(), img_view.width());

auto const kernel_up_offset = fixture::create_kernel<channel_t>(
{0, 0, 0, 0, 0, 0, 1, 0, 0});
gil::convolve_rows<pixel_t>(gil::const_view(img), kernel_up_offset,
gil::view(img_out_up_offset), gil::boundary_option::extend_reflection);

auto const kernel_down_offset = fixture::create_kernel<channel_t>(
{0, 0, 1, 0, 0, 0, 0, 0, 0});
gil::convolve_rows<pixel_t>(gil::const_view(img), kernel_down_offset,
gil::view(img_out_down_offset), gil::boundary_option::extend_reflection);

BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_up_offset),
gil::const_view(img_expected_up_offset)));
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_down_offset),
gil::const_view(img_expected_down_offset)));
}
static void run()
{
Expand Down
4 changes: 2 additions & 2 deletions test/extension/numeric/test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto create_kernel(std::initializer_list<T> const& values)
}

// Adds an offset similar to 1D row convolution with kernel {0, 0, 0, 0, 0, 0, 1, 0, 0}
// having its anchor point at 5th element and boundary option as "extend_zero".
// (for offset = 2) having its anchor point at 5th element and boundary option as "extend_zero".
template <typename SrcView, typename DstView>
void row_conv1D_offset_img_generator(SrcView src_view, DstView dst_view, int const offset,
std::ptrdiff_t start_row = 0, std::ptrdiff_t start_col = 0, std::ptrdiff_t end_row = -1,
Expand All @@ -56,7 +56,7 @@ void row_conv1D_offset_img_generator(SrcView src_view, DstView dst_view, int con
}

// Adds an offset similar to 1D column convolution with kernel {0, 0, 0, 0, 0, 0, 1, 0, 0}
// having its anchor point at 5th element and boundary option as "extend_zero".
// (for offset = 2) having its anchor point at 5th element and boundary option as "extend_zero".
template <typename SrcView, typename DstView>
void col_conv1D_offset_img_generator(SrcView src_view, DstView dst_view, int const offset,
std::ptrdiff_t start_row = 0, std::ptrdiff_t start_col = 0, std::ptrdiff_t end_row = -1,
Expand Down

0 comments on commit 060b66c

Please sign in to comment.