Skip to content

Commit

Permalink
new constant parameter added to threshold_adaptive
Browse files Browse the repository at this point in the history
  • Loading branch information
miralshah365 committed Jul 25, 2019
1 parent 7a3ff11 commit 692d878
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions include/boost/gil/image_processing/threshold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ void threshold_adaptive
typename channel_type<DstView>::type max_value,
std::size_t kernel_size,
threshold_adaptive_method method = threshold_adaptive_method::mean,
threshold_direction direction = threshold_direction::regular
threshold_direction direction = threshold_direction::regular,
typename channel_type<DstView>::type constant = 0
)
{
BOOST_ASSERT_MSG((kernel_size % 2 != 0), "Kernel size must be an odd number");
Expand All @@ -404,32 +405,28 @@ void threshold_adaptive

if (method == threshold_adaptive_method::mean)
{
float *mean = new float[kernel_size];
std::fill_n(mean, kernel_size, 1.0f/kernel_size);
std::vector<float> mean_kernel_values(kernel_size, 1.0f/kernel_size);
kernel_1d<float> kernel(mean_kernel_values.begin(), kernel_size, kernel_size/2);

image<typename SrcView::value_type> temp_img(src_view.width(), src_view.height());
typename image<typename SrcView::value_type>::view_t temp_view = view(temp_img);
SrcView temp_conv(temp_view);

kernel_1d<float> kernel(mean, kernel_size, kernel_size/2);
convolve_rows<pixel<float, typename SrcView::value_type::layout_t>>(

convolve<pixel<float, typename SrcView::value_type::layout_t>>(
src_view, kernel, temp_view
);
convolve_cols<pixel<float, typename SrcView::value_type::layout_t>>(
temp_view, kernel, temp_view
);

if (direction == threshold_direction::regular)
{
detail::adaptive_impl<source_channel_t, result_channel_t>(src_view, temp_conv, dst_view,
[max_value](source_channel_t px1, source_channel_t px2) -> result_channel_t
{ return px1 >= px2 ? max_value : 0; });
[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<source_channel_t, result_channel_t>(src_view, temp_conv, dst_view,
[max_value](source_channel_t px1, source_channel_t px2) -> result_channel_t
{ return px1 >= px2 ? 0 : max_value; });
[max_value, constant](source_channel_t px, source_channel_t threshold) -> result_channel_t
{ return px > (threshold - constant) ? 0 : max_value; });
}
}
}
Expand All @@ -441,15 +438,16 @@ void threshold_adaptive
DstView const& dst_view,
std::size_t kernel_size,
threshold_adaptive_method method = threshold_adaptive_method::mean,
threshold_direction direction = threshold_direction::regular
threshold_direction direction = threshold_direction::regular,
int constant = 0
)
{
//deciding output channel type and creating functor
typedef typename channel_type<DstView>::type result_channel_t;

result_channel_t max_value = std::numeric_limits<result_channel_t>::max();

threshold_adaptive(src_view, dst_view, max_value, kernel_size, method, direction);
threshold_adaptive(src_view, dst_view, max_value, kernel_size, method, direction, constant);
}

/// @}
Expand Down

0 comments on commit 692d878

Please sign in to comment.