Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 2D convolution definitions to numeric extension (#367)
2D convolution tests added `convolve` function renamed to `convolve_1d` closes #356
- Loading branch information
1 parent
499d30f
commit ca696ce
Showing
7 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <boost/gil/extension/numeric/kernel.hpp> | ||
#include <boost/gil/extension/numeric/convolve.hpp> | ||
#include <boost/gil/extension/io/png.hpp> | ||
|
||
#include <boost/gil/extension/io/jpeg.hpp> | ||
using namespace boost::gil; | ||
using namespace std; | ||
int main() | ||
{ | ||
//gray8_image_t img; | ||
//read_image("test_adaptive.png", img, png_tag{}); | ||
//gray8_image_t img_out(img.dimensions()); | ||
|
||
gray8_image_t img; | ||
read_image("src_view.png", img, png_tag{}); | ||
gray8_image_t img_out(img.dimensions()), img_out1(img.dimensions()); | ||
|
||
std::vector<float> v(9, 1.0f / 9.0f); | ||
kernel_2d<float> kernel(v.begin(), v.size(), 1, 1); | ||
convolve_2d(view(img), kernel, view(img_out1)); | ||
|
||
//write_view("out-convolve2d.png", view(img_out), png_tag{}); | ||
write_view("out-convolve2d.png", view(img_out1), jpeg_tag{}); | ||
|
||
|
||
//------------------------------------// | ||
std::vector<float> v1(3, 1.0f / 3.0f); | ||
kernel_1d<float> kernel1(v1.begin(), v1.size(), 1); | ||
|
||
convolve_1d<gray32f_pixel_t>(const_view(img), kernel1, view(img_out), convolve_boundary_option::convolve_option_extend_zero); | ||
write_view("out-convolve_option_extend_zero.png", view(img_out), png_tag{}); | ||
|
||
if (equal_pixels(view(img_out1), view(img_out)))cout << "convolve_option_extend_zero" << endl; | ||
|
||
cout << "done\n"; | ||
cin.get(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Copyright 2019 Miral Shah <miralshah2211@gmail.com> | ||
// | ||
// Use, modification and distribution are subject to the Boost Software License, | ||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#include <cstddef> | ||
|
||
#include <boost/gil.hpp> | ||
#include <boost/gil/extension/numeric/convolve.hpp> | ||
|
||
#define BOOST_TEST_MODULE test_ext_convolve_2d | ||
#include "unit_test.hpp" | ||
|
||
namespace gil = boost::gil; | ||
|
||
std::uint8_t img[] = | ||
{ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 255, 0, 0, 0, 255, 0, 0, | ||
0, 0, 0, 255, 0, 255, 0, 0, 0, | ||
0, 0, 0, 0, 255, 0, 0, 0, 0, | ||
0, 0, 0, 255, 0, 255, 0, 0, 0, | ||
0, 0, 255, 0, 0, 0, 255, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
}; | ||
|
||
std::uint8_t output[] = | ||
{ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 28, 28, 28, 0, 28, 28, 28, 0, | ||
0, 28, 56, 56, 56, 56, 56, 28, 0, | ||
0, 28, 56, 85, 85, 85, 56, 28, 0, | ||
0, 0, 56, 85, 141, 85, 56, 0, 0, | ||
0, 28, 56, 85, 85, 85, 56, 28, 0, | ||
0, 28, 56, 56, 56, 56, 56, 28, 0, | ||
0, 28, 28, 28, 0, 28, 28, 28, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
}; | ||
|
||
BOOST_AUTO_TEST_SUITE(convolve_2d) | ||
|
||
BOOST_AUTO_TEST_CASE(convolve_2d_with_normalized_mean_filter) | ||
{ | ||
gil::gray8c_view_t src_view = | ||
gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(img), 9); | ||
|
||
gil::image<gil::gray8_pixel_t> temp_img(src_view.width(), src_view.height()); | ||
typename gil::image<gil::gray8_pixel_t>::view_t temp_view = view(temp_img); | ||
gil::gray8_view_t dst_view(temp_view); | ||
|
||
std::vector<float> v(9, 1.0f / 9.0f); | ||
gil::kernel_2d<float> kernel(v.begin(), v.size(), 1, 1); | ||
|
||
gil::convolve_2d(src_view, kernel, dst_view); | ||
|
||
gil::gray8c_view_t out_view = | ||
gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(output), 9); | ||
|
||
BOOST_TEST(gil::equal_pixels(out_view, dst_view)); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |