diff --git a/include/boost/gil/image_processing/threshold.hpp b/include/boost/gil/image_processing/threshold.hpp index 0a4f579499..3eddc8674b 100644 --- a/include/boost/gil/image_processing/threshold.hpp +++ b/include/boost/gil/image_processing/threshold.hpp @@ -16,10 +16,12 @@ #include #include +#include + #include #include #include -#include +#include namespace boost { namespace gil { @@ -403,15 +405,15 @@ void threshold_adaptive typedef typename channel_type::type source_channel_t; typedef typename channel_type::type result_channel_t; + image temp_img(src_view.width(), src_view.height()); + typename image::view_t temp_view = view(temp_img); + SrcView temp_conv(temp_view); + if (method == threshold_adaptive_method::mean) { std::vector mean_kernel_values(kernel_size, 1.0f/kernel_size); kernel_1d kernel(mean_kernel_values.begin(), kernel_size, kernel_size/2); - image temp_img(src_view.width(), src_view.height()); - typename image::view_t temp_view = view(temp_img); - SrcView temp_conv(temp_view); - convolve_1d>( src_view, kernel, temp_view ); @@ -429,6 +431,34 @@ void threshold_adaptive { return px > (threshold - constant) ? 0 : max_value; }); } } + else if (method == threshold_adaptive_method::gaussian) + { + gray32f_image_t gaussian_kernel_values(kernel_size, kernel_size); + generate_gaussian_kernel(view(gaussian_kernel_values), 1.0); + + + kernel_2d kernel( + view(gaussian_kernel_values).begin(), + kernel_size * kernel_size, + kernel_size / 2, + kernel_size / 2 + ); + + convolve_2d(src_view, kernel, temp_view); + + if (direction == threshold_direction::regular) + { + detail::adaptive_impl(src_view, temp_conv, dst_view, + [max_value, constant](source_channel_t px, source_channel_t threshold) -> result_channel_t + { return px > (threshold - constant) ? max_value : 0; }); + } + else + { + detail::adaptive_impl(src_view, temp_conv, dst_view, + [max_value, constant](source_channel_t px, source_channel_t threshold) -> result_channel_t + { return px > (threshold - constant) ? 0 : max_value; }); + } + } } template