milena r3784: Fix full2image() domain for cropped images

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-05-11 Fabien Freling <fabien.freling@lrde.epita.fr> Fix full2image() domain for cropped images. * mln/core/concept/gpoint.hh: Add operator /. * mln/world/inter_pixel/all.hh: Add ful2image.hh inclusion. * mln/world/inter_pixel/full2image.hh: Fix domain. --- core/concept/gpoint.hh | 20 ++++++++++++++++---- world/inter_pixel/all.hh | 1 + world/inter_pixel/full2image.hh | 37 +++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 22 deletions(-) Index: trunk/milena/mln/world/inter_pixel/full2image.hh =================================================================== --- trunk/milena/mln/world/inter_pixel/full2image.hh (revision 3783) +++ trunk/milena/mln/world/inter_pixel/full2image.hh (revision 3784) @@ -31,14 +31,11 @@ /// \file mln/world/inter_pixel/full2image.hh /// /// Convert an inter-pixel image to a classical image. -/// -/// FIXME: will NOT work if the image has an origin different from (0,0). -# include <mln/core/image/image2d.hh> -# include <mln/geom/max_col.hh> -# include <mln/geom/max_row.hh> -# include <mln/geom/min_col.hh> -# include <mln/geom/min_row.hh> +# include <mln/core/concept/image.hh> +# include <mln/data/paste_without_localization.hh> +# include <mln/geom/nsites.hh> +# include <mln/world/inter_pixel/is_pixel.hh> namespace mln @@ -56,27 +53,31 @@ /// /// \return A classical image without inter-pixel data. // - template <typename T> - image2d<T> - full2image(const image2d<T>& input); + template <typename I> + I + full2image(const Image<I>& input); # ifndef MLN_INCLUDE_ONLY - template <typename T> - image2d<T> - full2image(const image2d<T>& input) + template <typename I> + I + full2image(const Image<I>& input_) { trace::entering("world::inter_pixel::full2image"); + + mlc_is_a(mln_domain(I), Box)::check(); + + const I& input = exact(input_); mln_precondition(input.is_valid()); - image2d<T> output((input.nrows() + 1) / 2, (input.ncols() + 1) / 2); + mln_domain(I) b(input.domain().pmin() / 2, + input.domain().pmax() / 2); + mln_concrete(I) output(b); + mln_assertion(geom::nsites(output) == geom::nsites(input | is_pixel())); - for (int row = geom::min_row(input); row <= geom::max_row(input); row += 2) - for (int col = geom::min_col(input); col <= geom::max_col(input); col += 2) - opt::at(output, row / 2, col / 2) = - opt::at(input, row, col); + data::paste_without_localization(input | is_pixel(), output); trace::exiting("world::inter_pixel::full2image"); return output; Index: trunk/milena/mln/world/inter_pixel/all.hh =================================================================== --- trunk/milena/mln/world/inter_pixel/all.hh (revision 3783) +++ trunk/milena/mln/world/inter_pixel/all.hh (revision 3784) @@ -38,6 +38,7 @@ # include <mln/world/inter_pixel/compute.hh> +# include <mln/world/inter_pixel/full2image.hh> # include <mln/world/inter_pixel/immerse.hh> # include <mln/world/inter_pixel/is_separator.hh> # include <mln/world/inter_pixel/is_pixel.hh> Index: trunk/milena/mln/core/concept/gpoint.hh =================================================================== --- trunk/milena/mln/core/concept/gpoint.hh (revision 3783) +++ trunk/milena/mln/core/concept/gpoint.hh (revision 3784) @@ -82,6 +82,13 @@ typedef L ret; }; + template < typename L, typename R > + struct set_binary_< op::div, + mln::Gpoint, L, + mln::Object, mln::value::scalar_<R> > + { + typedef L ret; + }; template <typename P> struct set_unary_< op::ord, mln::Gpoint, P > @@ -279,7 +286,7 @@ * \relates mln::Gpoint */ template <typename P, typename D> - P operator/(Gpoint<P>& p, const value::Scalar<D>& dp); + P operator/(const Gpoint<P>& p, const value::scalar_<D>& dp); // FIXME : add operators and traits? @@ -400,7 +407,7 @@ P operator*(const Gpoint<P>& p, const value::scalar_<S>& s) { - int s_ = s.to_equiv(); + S s_ = s.to_equiv(); const unsigned n = P::dim; P tmp = exact(p); for (unsigned i = 0; i < n; ++i) @@ -439,9 +446,14 @@ template <typename P, typename S> inline P - operator/(Gpoint<P>& p, const value::Scalar<S>& s_) + operator/(const Gpoint<P>& p, const value::scalar_<S>& s_) { - return p.to_vec() / s_; + S s = s_.to_equiv(); + const unsigned n = P::dim; + P tmp = exact(p); + for (unsigned i = 0; i < n; ++i) + tmp[i] /= s; + return tmp; } # endif // ! MLN_INCLUDE_ONLY
participants (1)
-
Fabien Freling