From 880b6e751eacfdfd6a39ffcb7f4828b73cf453a7 Mon Sep 17 00:00:00 2001 From: harsh-4 Date: Mon, 15 Mar 2021 18:44:23 +0530 Subject: [PATCH 1/2] Fix convolve_2d for images with float32_t channel model --- .../boost/gil/extension/numeric/convolve.hpp | 2 +- test/extension/numeric/convolve_2d.cpp | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/boost/gil/extension/numeric/convolve.hpp b/include/boost/gil/extension/numeric/convolve.hpp index a401b0028e..0c87202fc1 100644 --- a/include/boost/gil/extension/numeric/convolve.hpp +++ b/include/boost/gil/extension/numeric/convolve.hpp @@ -373,7 +373,7 @@ void convolve_2d_impl(SrcView const& src_view, DstView const& dst_view, Kernel c col_boundary >= 0 && col_boundary < src_view.width()) { aux_total += - src_view(col_boundary, row_boundary) * + src_view(col_boundary, row_boundary)[0] * kernel.at(flip_ker_row, flip_ker_col); } } diff --git a/test/extension/numeric/convolve_2d.cpp b/test/extension/numeric/convolve_2d.cpp index fbfce5f96c..b151c2ae92 100644 --- a/test/extension/numeric/convolve_2d.cpp +++ b/test/extension/numeric/convolve_2d.cpp @@ -60,9 +60,48 @@ void test_convolve_2d_with_normalized_mean_filter() BOOST_TEST(gil::equal_pixels(out_view, dst_view)); } +void test_convolve_2d_with_image_using_float32_t() +{ +gil::float32_t img[] = +{ + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.76, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.6, 0.6, 0.1, 0.54, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.84, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.1, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.3, 0.1, 0.1, 0.4, 0.1, 0.32, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.21, 0.1, 0.1 +}; + +gil::float32_t exp_output[] = +{ + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.76, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.6, 0.6, 0.1, 0.54, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.84, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.1, 0.1, 0.1, 0.4, 0.1, 0.5, 0.1, 0.1, + 0.1, 0.3, 0.1, 0.1, 0.4, 0.1, 0.32, 0.1, 0.1, + 0.1, 0.2, 0.1, 0.1, 0.4, 0.1, 0.21, 0.1, 0.1 +}; + +gil::gray32f_image_t img_gray_out(9, 9); +gil::gray32fc_view_t src_view = + gil::interleaved_view(9, 9, reinterpret_cast(img), 9); +gil::gray32fc_view_t exp_out_view = + gil::interleaved_view(9, 9, reinterpret_cast(exp_output), 9); +std::vector v(1, 1); +gil::detail::kernel_2d kernel(v.begin(), v.size(), 0, 0); //impulse kernel +gil::detail::convolve_2d(src_view, kernel, view(img_gray_out)); +BOOST_TEST(gil::equal_pixels(exp_out_view, view(img_gray_out))); +} + int main() { test_convolve_2d_with_normalized_mean_filter(); - + test_convolve_2d_with_image_using_float32_t(); return ::boost::report_errors(); } From b16d5a9ac0f8d029119164212645f7e86014fe99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Sat, 3 Apr 2021 00:49:26 +0200 Subject: [PATCH 2/2] Prefer eastconst; Add missing space --- test/extension/numeric/convolve_2d.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/extension/numeric/convolve_2d.cpp b/test/extension/numeric/convolve_2d.cpp index b151c2ae92..87efc7f6c2 100644 --- a/test/extension/numeric/convolve_2d.cpp +++ b/test/extension/numeric/convolve_2d.cpp @@ -90,11 +90,11 @@ gil::float32_t exp_output[] = gil::gray32f_image_t img_gray_out(9, 9); gil::gray32fc_view_t src_view = - gil::interleaved_view(9, 9, reinterpret_cast(img), 9); + gil::interleaved_view(9, 9, reinterpret_cast(img), 9); gil::gray32fc_view_t exp_out_view = - gil::interleaved_view(9, 9, reinterpret_cast(exp_output), 9); + gil::interleaved_view(9, 9, reinterpret_cast(exp_output), 9); std::vector v(1, 1); -gil::detail::kernel_2d kernel(v.begin(), v.size(), 0, 0); //impulse kernel +gil::detail::kernel_2d kernel(v.begin(), v.size(), 0, 0); // impulse kernel gil::detail::convolve_2d(src_view, kernel, view(img_gray_out)); BOOST_TEST(gil::equal_pixels(exp_out_view, view(img_gray_out))); }