milena r3560: Add ninds() method to image1d class

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-03-20 Fabien Freling <fabien.freling@lrde.epita.fr> Add ninds() method to image1d class. * mln/core/image/image1d.hh: Add ninds() method. * mln/world/binary_2d/projected_histo.hh: Update. --- core/image/image1d.hh | 13 +++++++++++++ world/binary_2d/projected_histo.hh | 19 ++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) Index: trunk/milena/mln/world/binary_2d/projected_histo.hh =================================================================== --- trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3559) +++ trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3560) @@ -47,11 +47,14 @@ { void projected_histo(const image2d<bool>& input, - image1d<value::int_u12>& row_histo, - image1d<value::int_u12>& col_histo) + image1d<float>& row_histo, + image1d<float>& col_histo, + bool value = true) { const unsigned nrows = input.nrows(); + data::fill(row_histo, 0); const unsigned ncols = input.ncols(); + data::fill(col_histo, 0); mln_precondition(row_histo.nelements() == nrows); mln_precondition(col_histo.nelements() == ncols); @@ -59,13 +62,19 @@ { for (unsigned col = 0; col < ncols; ++col) { - if (input(point2d(row, col))) + if (input.at_(row, col) == value) { - ++row_histo(point1d(row)); - ++col_histo(point1d(col)); + ++row_histo.at_(row); + ++col_histo.at_(col); } } } + + for (unsigned i = 0; i < row_histo.ninds(); ++i) + row_histo.at_(i) /= ncols; + + for (unsigned i = 0; i < col_histo.ninds(); ++i) + col_histo.at_(i) /= nrows; } } // end of namespace mln::world::binary_2d Index: trunk/milena/mln/core/image/image1d.hh =================================================================== --- trunk/milena/mln/core/image/image1d.hh (revision 3559) +++ trunk/milena/mln/core/image/image1d.hh (revision 3560) @@ -208,6 +208,10 @@ /// Read-write access to the image value located at (\p index). T& at_(def::coord index); + /// Give the number of indexes. + unsigned ninds() const; + + /// Fast Image method @@ -456,6 +460,15 @@ template <typename T> inline + unsigned + image1d<T>::ninds() const + { + mln_precondition(this->is_valid()); + return this->data_->b_.len(0); + } + + template <typename T> + inline T& image1d<T>::at_(def::coord index) {
participants (1)
-
Fabien Freling