8 #ifndef BOOST_GIL_IMAGE_PROCESSING_NUMERIC_HPP 9 #define BOOST_GIL_IMAGE_PROCESSING_NUMERIC_HPP 11 #include <boost/gil/detail/math.hpp> 13 #include <boost/gil/image_view.hpp> 14 #include <boost/gil/typedefs.hpp> 16 namespace boost {
namespace gil {
29 inline double normalized_sinc(
double x)
31 return std::sin(x * boost::gil::pi) / (x * boost::gil::pi);
41 inline double lanczos(
double x, std::ptrdiff_t a)
48 return normalized_sinc(x) / normalized_sinc(x / static_cast<double>(a));
61 if (dst.width() != dst.height() || dst.width() % 2 != 1)
62 throw std::invalid_argument(
"kernel dimensions should be odd and equal");
63 const float entry = 1.0f /
static_cast<float>(dst.size());
65 for (
auto&
pixel: dst) {
66 pixel.at(std::integral_constant<int, 0>{}) = entry;
76 if (dst.width() != dst.height() || dst.width() % 2 != 1)
77 throw std::invalid_argument(
"kernel dimensions should be odd and equal");
79 for (
auto&
pixel: dst) {
80 pixel.at(std::integral_constant<int, 0>{}) = 1.0f;
91 if (dst.width() != dst.height() || dst.width() % 2 != 1)
92 throw std::invalid_argument(
"kernel dimensions should be odd and equal");
94 const double denominator = 2 * boost::gil::pi * sigma * sigma;
96 for (boost::gil::gray32f_view_t::coord_t y = 0; y < dst.height(); ++y)
98 for (boost::gil::gray32f_view_t::coord_t x = 0; x < dst.width(); ++x)
100 const auto delta_x = std::abs(middle.x - x);
101 const auto delta_y = std::abs(middle.y - y);
102 const double power = (delta_x * delta_x + delta_y * delta_y) / (2 * sigma * sigma);
103 const double nominator = std::exp(-power);
104 const float value = nominator / denominator;
105 dst(x, y).at(std::integral_constant<int, 0>{}) = value;
Definition: algorithm.hpp:30
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept, PixelValueConcept, HomogeneousPixelBasedConcept.
Definition: metafunctions.hpp:23
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:41
void generate_normalized_mean(boost::gil::gray32f_view_t dst)
Generate mean kernelFills supplied view with normalized mean in which all entries will be equal to...
Definition: numeric.hpp:59
void generate_unnormalized_mean(boost::gil::gray32f_view_t dst)
Generate kernel with all 1sFills supplied view with 1s (ones)
Definition: numeric.hpp:74
void generate_gaussian_kernel(boost::gil::gray32f_view_t dst, double sigma)
Generate Gaussian kernelFills supplied view with values taken from Gaussian distribution. See https://en.wikipedia.org/wiki/Gaussian_blur.
Definition: numeric.hpp:89