File indexing completed on 2025-12-16 09:51:51
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_IMAGE_PROCESSING_HARRIS_HPP
0009 #define BOOST_GIL_IMAGE_PROCESSING_HARRIS_HPP
0010
0011 #include <boost/gil/image_view.hpp>
0012 #include <boost/gil/typedefs.hpp>
0013 #include <boost/gil/image_processing/kernel.hpp>
0014
0015 namespace boost { namespace gil {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <typename T, typename Allocator>
0034 void compute_harris_responses(
0035 boost::gil::gray32f_view_t m11,
0036 boost::gil::gray32f_view_t m12_21,
0037 boost::gil::gray32f_view_t m22,
0038 boost::gil::detail::kernel_2d<T, Allocator> weights,
0039 float k,
0040 boost::gil::gray32f_view_t harris_response)
0041 {
0042 if (m11.dimensions() != m12_21.dimensions() || m12_21.dimensions() != m22.dimensions()) {
0043 throw std::invalid_argument("m prefixed arguments must represent"
0044 " tensor from the same image");
0045 }
0046
0047 std::ptrdiff_t const window_length = weights.size();
0048 auto const width = m11.width();
0049 auto const height = m11.height();
0050 auto const half_length = window_length / 2;
0051
0052 for (auto y = half_length; y < height - half_length; ++y)
0053 {
0054 for (auto x = half_length; x < width - half_length; ++x)
0055 {
0056 float ddxx = 0;
0057 float dxdy = 0;
0058 float ddyy = 0;
0059 for (gil::gray32f_view_t::coord_t y_kernel = 0;
0060 y_kernel < window_length;
0061 ++y_kernel) {
0062 for (gil::gray32f_view_t::coord_t x_kernel = 0;
0063 x_kernel < window_length;
0064 ++x_kernel) {
0065 ddxx += m11(x + x_kernel - half_length, y + y_kernel - half_length)
0066 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
0067 dxdy += m12_21(x + x_kernel - half_length, y + y_kernel - half_length)
0068 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
0069 ddyy += m22(x + x_kernel - half_length, y + y_kernel - half_length)
0070 .at(std::integral_constant<int, 0>{}) * weights.at(x_kernel, y_kernel);
0071 }
0072 }
0073 auto det = (ddxx * ddyy) - dxdy * dxdy;
0074 auto trace = ddxx + ddyy;
0075 auto harris_value = det - k * trace * trace;
0076 harris_response(x, y).at(std::integral_constant<int, 0>{}) = harris_value;
0077 }
0078 }
0079 }
0080
0081 }}
0082 #endif