Skip to content

Commit

Permalink
Fix convolve_2d for images with float32_t channel model (#577)
Browse files Browse the repository at this point in the history
Fixes #575
  • Loading branch information
harshitpant1 committed Feb 9, 2022
1 parent 5dcdf53 commit c7aba23
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/boost/gil/extension/numeric/convolve.hpp
Expand Up @@ -399,7 +399,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);
}
}
Expand Down
41 changes: 40 additions & 1 deletion test/extension/numeric/convolve_2d.cpp
Expand Up @@ -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<gil::gray32f_pixel_t const*>(img), 9);
gil::gray32fc_view_t exp_out_view =
gil::interleaved_view(9, 9, reinterpret_cast<gil::gray32f_pixel_t const*>(exp_output), 9);
std::vector<float> v(1, 1);
gil::detail::kernel_2d<float> 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();
}

0 comments on commit c7aba23

Please sign in to comment.