Boost GIL


hough_parameter.hpp
1 // Boost.GIL (Generic Image Library) - tests
2 //
3 // Copyright 2020 Olzhas Zhumabek <anonymous.from.applecity@gmail.com>
4 //
5 // Use, modification and distribution are subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 #ifndef BOOST_GIL_IMAGE_PROCESSING_HOUGH_PARAMETER_HPP
10 #define BOOST_GIL_IMAGE_PROCESSING_HOUGH_PARAMETER_HPP
11 
12 #include <boost/gil/point.hpp>
13 #include <cmath>
14 #include <cstddef>
15 
16 namespace boost
17 {
18 namespace gil
19 {
25 template <typename T>
27 {
28  T start_point;
29  T step_size;
30  std::size_t step_count;
31 
38  static hough_parameter<T> from_step_count(T start_point, T neighborhood,
39  std::size_t half_step_count)
40  {
41  T step_size = neighborhood / half_step_count;
42  std::size_t step_count = half_step_count * 2 + 1;
43  // explicitly fill out members, as aggregate init will error out with narrowing
44  hough_parameter<T> parameter;
45  parameter.start_point = start_point - neighborhood;
46  parameter.step_size = step_size;
47  parameter.step_count = step_count;
48  return parameter;
49  }
50 
57  static hough_parameter<T> from_step_size(T start_point, T neighborhood, T step_size)
58  {
59  std::size_t step_count =
60  2 * static_cast<std::size_t>(std::floor(neighborhood / step_size)) + 1;
61  // do not use step_size - neighborhood, as step_size might not allow
62  // landing exactly on that value when starting from start_point
63  // also use parentheses on step_count / 2 because flooring is exactly
64  // what we want
65 
66  // explicitly fill out members, as aggregate init will error out with narrowing
67  hough_parameter<T> parameter;
68  parameter.start_point = start_point - step_size * (step_count / 2);
69  parameter.step_size = step_size;
70  parameter.step_count = step_count;
71  return parameter;
72  }
73 };
74 
85 inline double minimum_angle_step(point_t dimensions)
86 {
87  auto longer_dimension = dimensions.x > dimensions.y ? dimensions.x : dimensions.y;
88  return std::atan2(1, longer_dimension);
89 }
90 
101 inline hough_parameter<double> make_theta_parameter(double approx_angle, double neighborhood,
102  point_t dimensions)
103 {
104  auto angle_step = minimum_angle_step(dimensions);
105 
106  // std::size_t step_count =
107  // 2 * static_cast<std::size_t>(std::floor(neighborhood / angle_step)) + 1;
108  // return {approx_angle - angle_step * (step_count / 2), angle_step, step_count};
109  return hough_parameter<double>::from_step_size(approx_angle, neighborhood, angle_step);
110 }
111 }} // namespace boost::gil
112 #endif
boost::gil::hough_parameter::from_step_count
static hough_parameter< T > from_step_count(T start_point, T neighborhood, std::size_t half_step_count)
Create Hough parameter from value neighborhood and step count.
Definition: hough_parameter.hpp:38
boost::gil::minimum_angle_step
double minimum_angle_step(point_t dimensions)
Calculate minimum angle which would be observable if walked on a circle.
Definition: hough_parameter.hpp:85
boost::gil::make_theta_parameter
hough_parameter< double > make_theta_parameter(double approx_angle, double neighborhood, point_t dimensions)
Create a Hough transform parameter with optimal angle step.
Definition: hough_parameter.hpp:101
boost::gil::hough_parameter
A type to encapsulate Hough transform parameter range.
Definition: hough_parameter.hpp:26
boost::gil::hough_parameter::from_step_size
static hough_parameter< T > from_step_size(T start_point, T neighborhood, T step_size)
Create Hough parameter from value neighborhood and step size.
Definition: hough_parameter.hpp:57
boost::gil::point< std::ptrdiff_t >