$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hough.hh
1 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_TRANSFORM_HOUGH_HH
28 # define MLN_TRANSFORM_HOUGH_HH
29 
33 
34 
35 # include <mln/core/image/image2d.hh>
36 # include <mln/data/fill.hh>
37 
38 # include <mln/geom/nrows.hh>
39 # include <mln/geom/ncols.hh>
40 # include <mln/geom/min_col.hh>
41 # include <mln/geom/min_row.hh>
42 # include <mln/geom/bbox.hh>
43 
44 # include <mln/opt/at.hh>
45 
46 # include <mln/math/sin.hh>
47 # include <mln/math/cos.hh>
48 # include <mln/math/pi.hh>
49 
50 # include <mln/make/box2d.hh>
51 
52 # include <mln/value/int_u8.hh>
53 
54 
55 namespace mln
56 {
57 
58  namespace transform
59  {
60 
76  template <typename I>
77  image2d<float>
78  hough(const Image<I>& input_);
79 
80 
81 
82 # ifndef MLN_INCLUDE_ONLY
83 
84 
85  namespace internal
86  {
87 
88 
90  double to_radians(double angle)
91  {
92  return angle * math::pi / 180.0f;
93  }
94 
95 
96  } // end of namespace mln::transform::internal
97 
98 
99 
100  template <typename I>
101  image2d<float>
102  hough(const Image<I>& input_)
103  {
104  mln_trace("mln::transform::hough");
105 
106  const I& input = exact(input_);
107  mlc_equal(mln_value(I), bool)::check();
108  mln_precondition(input.is_valid());
109 
110  def::coord
111  minrow = geom::min_row(input),
112  mincol = geom::min_col(input);
113  unsigned
114  ncols = geom::ncols(input),
115  nrows = geom::nrows(input);
116  int maxRho = (int)(sqrt((ncols * nrows)
117  + (ncols * nrows))
118  + 0.5);
119 
120  image2d<float> accu(360, 2*maxRho);
121  data::fill(accu, 0.f);
122 
123  mln_piter(image2d<int>) p(input.domain());
124  for_all(p)
125  if (input(p))
126  for (int angle = 0 ; angle < 360 ; ++angle)
127  {
128  double
129  theta = internal::to_radians(angle),
130  rho = (p.row() - minrow) * math::cos(theta)
131  + (p.col() - mincol) * math::sin(theta);
132  int
133  indexAngle = (int) (angle),
134  indexRho = (int)(rho + maxRho + 0.5);
135 
136  ++opt::at(accu, indexAngle, indexRho);
137  }
138 
139  return accu;
140  }
141 
142 
143 # endif // ! MLN_INCLUDE_ONLY
144 
145  } // end of namespace mln::transform
146 
147 } // end of namespace mln
148 
149 
150 #endif // ! MLN_TRANSFORM_HOUGH_HH