8 #ifndef BOOST_GIL_IMAGE_PROCESSING_HARRIS_HPP 9 #define BOOST_GIL_IMAGE_PROCESSING_HARRIS_HPP 11 #include <boost/gil/image_view.hpp> 12 #include <boost/gil/typedefs.hpp> 13 #include <boost/gil/extension/numeric/kernel.hpp> 15 namespace boost {
namespace gil {
33 template <
typename T,
typename Allocator>
35 boost::gil::gray32f_view_t m11,
36 boost::gil::gray32f_view_t m12_21,
37 boost::gil::gray32f_view_t m22,
38 boost::gil::detail::kernel_2d<T, Allocator> weights,
40 boost::gil::gray32f_view_t harris_response)
42 if (m11.dimensions() != m12_21.dimensions() || m12_21.dimensions() != m22.dimensions()) {
43 throw std::invalid_argument(
"m prefixed arguments must represent" 44 " tensor from the same image");
47 auto const window_length = weights.size();
48 auto const width = m11.width();
49 auto const height = m11.height();
50 auto const half_length = window_length / 2;
52 for (
auto y = half_length; y < height - half_length; ++y)
54 for (
auto x = half_length; x < width - half_length; ++x)
59 for (gil::gray32f_view_t::coord_t y_kernel = 0;
60 y_kernel < window_length;
62 for (gil::gray32f_view_t::coord_t x_kernel = 0;
63 x_kernel < window_length;
65 ddxx += m11(x + x_kernel - half_length, y + y_kernel - half_length)
66 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
67 dxdy += m12_21(x + x_kernel - half_length, y + y_kernel - half_length)
68 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
69 ddyy += m22(x + x_kernel - half_length, y + y_kernel - half_length)
70 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
73 auto det = (ddxx * ddyy) - dxdy * dxdy;
74 auto trace = ddxx + ddyy;
75 auto harris_value = det - k * trace * trace;
76 harris_response(x, y).at(std::integral_constant<int, 0>{}) = harris_value;
void compute_harris_responses(boost::gil::gray32f_view_t m11, boost::gil::gray32f_view_t m12_21, boost::gil::gray32f_view_t m22, boost::gil::detail::kernel_2d< T, Allocator > weights, float k, boost::gil::gray32f_view_t harris_response)
function to record Harris responsesThis algorithm computes Harris responses for structure tensor repr...
Definition: harris.hpp:34