milena r3563: Conversion from util::array to image1d

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-03-24 Fabien Freling <fabien.freling@lrde.epita.fr> Conversion from util::array to image1d. * mln/convert/from_to.hxx: Update from_to for image1d. * mln/core/image/image1d.hh: Update from_to. * mln/world/binary_2d/projected_histo.hh: Update. --- convert/from_to.hxx | 5 +++++ core/image/image1d.hh | 15 +++++++++++++++ world/binary_2d/projected_histo.hh | 17 ++++++++++------- 3 files changed, 30 insertions(+), 7 deletions(-) Index: trunk/milena/mln/world/binary_2d/projected_histo.hh =================================================================== --- trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3562) +++ trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3563) @@ -32,9 +32,12 @@ /// /// FIXME: insert comment. +# include <mln/core/concept/image.hh> # include <mln/core/image/image1d.hh> # include <mln/core/image/image2d.hh> # include <mln/core/alias/dpoint2d.hh> +# include <mln/geom/all.hh> +# include <mln/opt/at.hh> # include <mln/value/int_u12.hh> # include <mln/util/couple.hh> @@ -47,25 +50,25 @@ namespace binary_2d { + template <typename I> util::couple<image1d<float>, image1d<float> > - projected_histo(const image2d<bool>& input, bool value = true) + projected_histo(const Image<I>& input_, bool value = true) { - const unsigned nrows = input.nrows(); + mln_ch_value(I, bool) input = exact(input_); + + const unsigned nrows = geom::nrows(input); image1d<float> row_histo(nrows); data::fill(row_histo, 0); - const unsigned ncols = input.ncols(); + const unsigned ncols = geom::ncols(input); image1d<float> col_histo(ncols); data::fill(col_histo, 0); - mln_precondition(row_histo.nelements() == nrows); - mln_precondition(col_histo.nelements() == ncols); - for (unsigned row = 0; row < nrows; ++row) { for (unsigned col = 0; col < ncols; ++col) { - if (input.at_(row, col) == value) + if (opt::at(input, geom::bbox(input).min_row() + row, geom::bbox(input).min_col() + col) == value) { ++row_histo.at_(row); ++col_histo.at_(col); Index: trunk/milena/mln/core/image/image1d.hh =================================================================== --- trunk/milena/mln/core/image/image1d.hh (revision 3562) +++ trunk/milena/mln/core/image/image1d.hh (revision 3563) @@ -133,6 +133,10 @@ template <typename V, typename T> void from_to_(const histo::array<V>& from, image1d<T>& to); + // util::array -> image1d. + template <typename V, typename T> + void from_to_(const util::array<V>& from, image1d<T>& to); + } // end of namespace mln::convert::over_load } // end of namespace mln::convert @@ -577,6 +581,17 @@ from_to(from[i], to(point1d(i))); } + // util::array -> image1d. + template <typename V, typename T> + inline + void + from_to_(const util::array<V>& from, image1d<T>& to) + { + to.init_(make::box1d(from.nelements()), 0); + for (unsigned i = 0; i < from.nelements(); ++i) + from_to(from[i], to(point1d(i))); + } + } // end of namespace mln::convert::over_load } // end of namespace mln::convert Index: trunk/milena/mln/convert/from_to.hxx =================================================================== --- trunk/milena/mln/convert/from_to.hxx (revision 3562) +++ trunk/milena/mln/convert/from_to.hxx (revision 3563) @@ -418,6 +418,11 @@ void from_to_(const histo::array<V>& from, image1d<T>& to); + // util::array -> image1d + template <typename V, typename T> + void + from_to_(const util::array<V>& from, image1d<T>& to); + } // end of namespace mln::convert::over_load } // end of namespace mln::convert
participants (1)
-
Fabien Freling