Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix convolve_2d for images with float32_t channel model #577

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/gil/extension/numeric/convolve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] *
mloskot marked this conversation as resolved.
Show resolved Hide resolved
kernel.at(flip_ker_row, flip_ker_col);
}
}
Expand Down
41 changes: 40 additions & 1 deletion test/extension/numeric/convolve_2d.cpp
Original file line number Diff line number Diff line change
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();
}