8 #ifndef BOOST_GIL_IMAGE_PROCESSING_NUMERIC_HPP     9 #define BOOST_GIL_IMAGE_PROCESSING_NUMERIC_HPP    11 #include <boost/gil/extension/numeric/kernel.hpp>    12 #include <boost/gil/extension/numeric/convolve.hpp>    13 #include <boost/gil/image_view.hpp>    14 #include <boost/gil/typedefs.hpp>    15 #include <boost/gil/detail/math.hpp>    20 namespace boost { 
namespace gil {
    33 inline double normalized_sinc(
double x)
    35     return std::sin(x * boost::gil::detail::pi) / (x * boost::gil::detail::pi);
    45 inline double lanczos(
double x, std::ptrdiff_t a)
    52         return normalized_sinc(x) / normalized_sinc(x / static_cast<double>(a));
    57 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)    59 #pragma warning(disable:4244) // 'argument': conversion from 'const Channel' to 'BaseChannelValue', possible loss of data    62 inline void compute_tensor_entries(
    63     boost::gil::gray16s_view_t dx,
    64     boost::gil::gray16s_view_t dy,
    65     boost::gil::gray32f_view_t m11,
    66     boost::gil::gray32f_view_t m12_21,
    67     boost::gil::gray32f_view_t m22)
    69     for (std::ptrdiff_t y = 0; y < dx.height(); ++y) {
    70         for (std::ptrdiff_t x = 0; x < dx.width(); ++x) {
    71             auto dx_value = dx(x, y);
    72             auto dy_value = dy(x, y);
    73             m11(x, y) = dx_value * dx_value;
    74             m12_21(x, y) = dx_value * dy_value;
    75             m22(x, y) = dy_value * dy_value;
    80 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)    90 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
    93     if (side_length % 2 != 1)
    94         throw std::invalid_argument(
"kernel dimensions should be odd and equal");
    95     const float entry = 1.0f / static_cast<float>(side_length * side_length);
    97     detail::kernel_2d<T, Allocator> result(side_length, side_length / 2, side_length / 2);
    98     for (
auto& cell: result) {
   109 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   112     if (side_length % 2 != 1)
   113         throw std::invalid_argument(
"kernel dimensions should be odd and equal");
   115     detail::kernel_2d<T, Allocator> result(side_length, side_length / 2, side_length / 2);
   116     for (
auto& cell: result) {
   128 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   131     if (side_length % 2 != 1)
   132         throw std::invalid_argument(
"kernel dimensions should be odd and equal");
   135     const double denominator = 2 * boost::gil::detail::pi * sigma * sigma;
   136     auto middle = side_length / 2;
   137     std::vector<T, Allocator> values(side_length * side_length);
   138     for (std::size_t y = 0; y < side_length; ++y)
   140         for (std::size_t x = 0; x < side_length; ++x)
   142             const auto delta_x = middle > x ? middle - x : x - middle;
   143             const auto delta_y = middle > y ? middle - y : y - middle;
   144             const double power = (delta_x * delta_x +  delta_y * delta_y) / (2 * sigma * sigma);
   145             const double nominator = std::exp(-power);
   146             const float value = static_cast<float>(nominator / denominator);
   147             values[y * side_length + x] = value;
   151     return detail::kernel_2d<T, Allocator>(values.begin(), values.size(), middle, middle);
   161 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   168             return detail::get_identity_kernel<T, Allocator>();
   172             detail::kernel_2d<T, Allocator> result(3, 1, 1);
   173             std::copy(detail::dx_sobel.begin(), detail::dx_sobel.end(), result.begin());
   177             throw std::logic_error(
"not supported yet");
   181     throw std::runtime_error(
"unreachable statement");
   191 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   198             return detail::get_identity_kernel<T, Allocator>();
   202             detail::kernel_2d<T, Allocator> result(3, 1, 1);
   203             std::copy(detail::dx_scharr.begin(), detail::dx_scharr.end(), result.begin());
   207             throw std::logic_error(
"not supported yet");
   211     throw std::runtime_error(
"unreachable statement");
   221 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   228             return detail::get_identity_kernel<T, Allocator>();
   232             detail::kernel_2d<T, Allocator> result(3, 1, 1);
   233             std::copy(detail::dy_sobel.begin(), detail::dy_sobel.end(), result.begin());
   237             throw std::logic_error(
"not supported yet");
   241     throw std::runtime_error(
"unreachable statement");
   251 template <
typename T = 
float, 
typename Allocator = std::allocator<T>>
   258             return detail::get_identity_kernel<T, Allocator>();
   262             detail::kernel_2d<T, Allocator> result(3, 1, 1);
   263             std::copy(detail::dy_scharr.begin(), detail::dy_scharr.end(), result.begin());
   267             throw std::logic_error(
"not supported yet");
   271     throw std::runtime_error(
"unreachable statement");
   283 template <
typename GradientView, 
typename OutputView>
   293     detail::convolve_2d(dx, sobel_x, ddxx);
   294     detail::convolve_2d(dx, sobel_y, dxdy);
   295     detail::convolve_2d(dy, sobel_y, ddyy);
 detail::kernel_2d< T, Allocator > generate_dy_sobel(unsigned int degree=1)
Generates Sobel operator in vertical directionGenerates a kernel which will represent Sobel operator ...
Definition: numeric.hpp:222
void compute_hessian_entries(GradientView dx, GradientView dy, OutputView ddxx, OutputView dxdy, OutputView ddyy)
Compute xy gradient, and second order x and y gradientsHessian matrix is defined as a matrix of parti...
Definition: numeric.hpp:284
double lanczos(double x, std::ptrdiff_t a)
Lanczos response at point xLanczos response is defined as: x == 0: 1 -a < x && x < a: 0 otherwise: no...
Definition: numeric.hpp:45
BOOST_FORCEINLINE auto copy(boost::gil::pixel< T, CS > *first, boost::gil::pixel< T, CS > *last, boost::gil::pixel< T, CS > *dst) -> boost::gil::pixel< T, CS > *
Copy when both src and dst are interleaved and of the same type can be just memmove.
Definition: algorithm.hpp:139
detail::kernel_2d< T, Allocator > generate_dx_scharr(unsigned int degree=1)
Generate Scharr operator in horizontal directionGenerates a kernel which will represent Scharr operat...
Definition: numeric.hpp:192
detail::kernel_2d< T, Allocator > generate_dx_sobel(unsigned int degree=1)
Generates Sobel operator in horizontal directionGenerates a kernel which will represent Sobel operato...
Definition: numeric.hpp:162
detail::kernel_2d< T, Allocator > generate_unnormalized_mean(std::size_t side_length)
Generate kernel with all 1sFills supplied view with 1s (ones)
Definition: numeric.hpp:110
detail::kernel_2d< T, Allocator > generate_dy_scharr(unsigned int degree=1)
Generate Scharr operator in vertical directionGenerates a kernel which will represent Scharr operator...
Definition: numeric.hpp:252
detail::kernel_2d< T, Allocator > generate_gaussian_kernel(std::size_t side_length, double sigma)
Generate Gaussian kernelFills supplied view with values taken from Gaussian distribution....
Definition: numeric.hpp:129
detail::kernel_2d< T, Allocator > generate_normalized_mean(std::size_t side_length)
Generate mean kernelFills supplied view with normalized mean in which all entries will be equal to.
Definition: numeric.hpp:91