Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_TRANSFORM_HOUGH_HH 00027 # define MLN_TRANSFORM_HOUGH_HH 00028 00032 00033 00034 # include <mln/core/image/image2d.hh> 00035 # include <mln/data/fill.hh> 00036 00037 # include <mln/geom/nrows.hh> 00038 # include <mln/geom/ncols.hh> 00039 # include <mln/geom/min_col.hh> 00040 # include <mln/geom/min_row.hh> 00041 # include <mln/geom/bbox.hh> 00042 00043 # include <mln/opt/at.hh> 00044 00045 # include <mln/math/sin.hh> 00046 # include <mln/math/cos.hh> 00047 # include <mln/math/pi.hh> 00048 00049 # include <mln/make/box2d.hh> 00050 00051 # include <mln/value/int_u8.hh> 00052 00053 00054 namespace mln 00055 { 00056 00057 namespace transform 00058 { 00059 00071 // 00072 template <typename I> 00073 image2d<float> 00074 hough(const Image<I>& input_); 00075 00076 00077 00078 # ifndef MLN_INCLUDE_ONLY 00079 00080 00081 namespace internal 00082 { 00083 00084 00086 double to_radians(double angle) 00087 { 00088 return angle * math::pi / 180.0f; 00089 } 00090 00091 00092 } // end of namespace mln::transform::internal 00093 00094 00095 00096 template <typename I> 00097 image2d<float> 00098 hough(const Image<I>& input_) 00099 { 00100 trace::entering("mln::transform::hough"); 00101 00102 const I& input = exact(input_); 00103 mlc_equal(mln_value(I), bool)::check(); 00104 mln_precondition(input.is_valid()); 00105 00106 def::coord 00107 minrow = geom::min_row(input), 00108 mincol = geom::min_col(input); 00109 unsigned 00110 ncols = geom::ncols(input), 00111 nrows = geom::nrows(input); 00112 int maxRho = (int)(sqrt((ncols * nrows) 00113 + (ncols * nrows)) 00114 + 0.5); 00115 00116 image2d<float> accu(360, 2*maxRho); 00117 data::fill(accu, 0.f); 00118 00119 mln_piter(image2d<int>) p(input.domain()); 00120 for_all(p) 00121 if (input(p)) 00122 for (int angle = 0 ; angle < 360 ; ++angle) 00123 { 00124 double 00125 theta = internal::to_radians(angle), 00126 rho = (p.row() - minrow) * math::cos(theta) 00127 + (p.col() - mincol) * math::sin(theta); 00128 int 00129 indexAngle = (int) (angle), 00130 indexRho = (int)(rho + maxRho + 0.5); 00131 00132 ++opt::at(accu, indexAngle, indexRho); 00133 } 00134 00135 trace::exiting("mln::transform::hough"); 00136 return accu; 00137 } 00138 00139 00140 # endif // ! MLN_INCLUDE_ONLY 00141 00142 } // end of namespace mln::transform 00143 00144 } // end of namespace mln 00145 00146 00147 #endif // ! MLN_TRANSFORM_HOUGH_HH