
ima 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 elementary_erosion 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 elementary_dilation 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 erosion_w 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 dilation_w 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 elementary_opening 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 elementary_closing 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 opening 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 closing 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Basic Morpho : Tested OK. * oln/core/2d/image2d.hh: . * oln/morpho/elementary_erosion.hh: . * oln/morpho/elementary_closing.hh: . * oln/morpho/elementary_opening.hh: . * oln/morpho/erosion.hh: . * oln/morpho/closing.hh: . * oln/morpho/opening.hh: . * oln/level/local.hh: . * oln/level/apply_local.hh: . level/apply_local.hh | 28 ++++++++++++ level/local.hh | 100 ++++++++++++++++++++++--------------------- morpho/closing.hh | 5 -- morpho/elementary_closing.hh | 6 -- morpho/elementary_erosion.hh | 3 - morpho/elementary_opening.hh | 6 -- morpho/erosion.hh | 2 morpho/opening.hh | 6 +- 8 files changed, 91 insertions(+), 65 deletions(-) Index: oln/core/2d/image2d.hh Index: oln/morpho/elementary_erosion.hh --- oln/morpho/elementary_erosion.hh (revision 896) +++ oln/morpho/elementary_erosion.hh (working copy) @@ -65,12 +65,11 @@ template <typename I> oln_plain(I) elementary_erosion_on_set_(const Image<I>&, - const I&) + const I& input) { border::fill(input, oln_max(oln_value(I))); accumulator::and_<oln_value(I)> accu_and; return level::apply_local(accu_and, input); - return tmp; } Index: oln/morpho/elementary_closing.hh --- oln/morpho/elementary_closing.hh (revision 896) +++ oln/morpho/elementary_closing.hh (working copy) @@ -52,11 +52,9 @@ template <typename I> oln_plain(I) - elementary_closing_(const Image<I>& input); + elementary_closing_(const Image_with_Nbh<I>& input) { - oln_plain(I) tmp; - tmp = elementary_dilation(input); - return elementary_erosion(tmp); + return elementary_erosion( elementary_dilation(input) ); } // FIXME: Add a fast version. Index: oln/morpho/elementary_opening.hh --- oln/morpho/elementary_opening.hh (revision 896) +++ oln/morpho/elementary_opening.hh (working copy) @@ -52,11 +52,9 @@ template <typename I> oln_plain(I) - elementary_opening_(const Image<I>& input); + elementary_opening_(const Image_with_Nbh<I>& input) { - oln_plain(I) tmp; - tmp = elementary_erosion(input); - return elementary_dilation(tmp); + return morpho::elementary_dilation( morpho::elementary_erosion(input) ); } // FIXME: Add a fast version. Index: oln/morpho/erosion.hh --- oln/morpho/erosion.hh (revision 896) +++ oln/morpho/erosion.hh (working copy) @@ -58,7 +58,7 @@ { border::fill(input, oln_min(oln_value(I))); accumulator::min_<oln_value(I)> min; - return level::apply_local(max, input, win); + return level::apply_local(min, input, win); } template <typename I> Index: oln/morpho/closing.hh --- oln/morpho/closing.hh (revision 896) +++ oln/morpho/closing.hh (working copy) @@ -56,14 +56,13 @@ closing_(const Image<I>& input, const Window<W>& win) { - oln_plain(I) = elementary_dilation(input, win); - return elementary_erosion(tmp, win); // FIXME : inverse(win). + oln_plain(I) tmp = morpho::dilation(input, win); + return morpho::erosion(tmp, win); // FIXME : inverse(win). } // FIXME: Add a fast version. - } // end of namespace oln::morpho::impl Index: oln/morpho/opening.hh --- oln/morpho/opening.hh (revision 896) +++ oln/morpho/opening.hh (working copy) @@ -56,8 +56,8 @@ opening_(const Image<I>& input, const Window<W>& win) { - oln_plain(I) = elementary_dilation(input, win); - return elementary_erosion(tmp, win); // FIXME : inverse(win). + oln_plain(I) tmp = morpho::dilation(input, win); + return morpho::erosion(tmp, win); // FIXME : inverse(win). } // FIXME: Add a fast version. @@ -71,7 +71,7 @@ oln_plain(I) opening(const Image<I>& input, const Window<W>& win) { - return impl::opening_(exact(input), exact(win)); + return impl::opening_(exact(input), win); } # endif // ! OLN_INCLUDE_ONLY Index: oln/level/local.hh --- oln/level/local.hh (revision 896) +++ oln/level/local.hh (working copy) @@ -59,6 +59,8 @@ namespace impl { + /// Neigborhood. + // Generic version with neighborhood. template <typename A, typename I> @@ -70,36 +72,18 @@ f.init_with(input(p)); oln_niter(I) n(p, input); for_all(n) + { f(input(n)); - return f.value(); } - - - // FIXME: Generic version with nbh given as argument? - - // Generic version with window. - - template <typename A, typename I, typename W> - typename A::result - local_(const A& f, - const Image<I>& input, - const oln_point(I)& p, - const Window<W>& win) - { - f.init(); - oln_qiter(W) q(p, win); - for_all(q) - f(input(q)); return f.value(); } - // Optimised version for OR operator with neighborhood. template <typename B, typename I> B - local_(const accumulator::or_<B>& f, - const Binary_Image<I>& input, + local_(const oln::accumulator::or_<B>& f, + const Image_with_Nbh<I>& input, const oln_point(I)& p) { f.init_with(input(p)); @@ -115,55 +99,74 @@ return f.value(); } + // Optimised version for AND operator with neighborhood. - // Optimised version for OR operator with window. - - template <typename B, typename I, typename W> + template <typename B, typename I> B - local_(const accumulator::or_<B>& f, - const Binary_Image<I>& input, + local_(const accumulator::and_< B > f, + const Image_with_Nbh<I>& input, + const oln_point(I)& p) + { + f.init_with(input(p)); + oln_niter(I) n(p, input); + for_all(n) + { + f(input(n)); // FIXME: Change to f.take(input(n))? + if (f.value() == false) + return false; + } + return f.value(); + } + + // FIXME: Generic version with nbh given as argument? + + + + /// On Window. + + // Generic version with window. + + template <typename A, typename I, typename W> + typename A::result + local_(const A& f, + const Image<I>& input, const oln_point(I)& p, const Window<W>& win) { f.init_with(input(p)); - if (f.value() == true) - return true; oln_qiter(W) q(p, win); for_all(q) - { + if (input.owns_(q)) f(input(q)); - if (f.value() == true) - return true; - } return f.value(); } + // Optimised version for OR operator with window. - // FIXME : same function for OR. - - // Optimised version for AND operator with neighborhood. - - template <typename B, typename I> + template <typename B, typename I, typename W> B - local_(const accumulator::and_< B > f, + local_(const oln::accumulator::or_<B>& f, const Binary_Image<I>& input, - const oln_point(I)& p) + const oln_point(I)& p, + const Window<W>& win) { f.init_with(input(p)); - oln_niter(I) n(p, input); - for_all(n) + if (f.value() == true) + return true; + oln_qiter(W) q(p, win); + for_all(q) { - f(input(n)); // FIXME: Change to f.take(input(n))? + if (input.owns_(q)) + f(input(q)); if (f.value() == true) return true; } return f.value(); } - // Optimised version for AND operator with window. - template <typename A, typename I, typename W> + template <typename B, typename I, typename W> B local_(const accumulator::and_< B > f, const Image<I>& input, @@ -174,9 +177,10 @@ oln_qiter(W) q(p, win); for_all(q) { + if (input.owns_(q)) f(input(q)); - if (f.value() == true) - return true; + if (f.value() == false) + return false; } return f.value(); } @@ -192,7 +196,7 @@ const Image_with_Nbh<I>& input, const oln_point(I)& p) { - return impl::local_(exact(f), input, p); + return impl::local_(exact(f), exact(input), p); } template <typename A, typename I, typename W> @@ -202,7 +206,7 @@ const oln_point(I)& p, const Window<W>& win) { - return impl::local_(exact(f), input, p, win); + return impl::local_(exact(f), exact(input), p, win); } #endif // ! OLN_INCLUDE_ONLY Index: oln/level/apply_local.hh --- oln/level/apply_local.hh (revision 896) +++ oln/level/apply_local.hh (working copy) @@ -47,6 +47,11 @@ apply_local(const Accumulator<F>& f, const Image_with_Nbh<I>& input); + template <typename F, typename I, typename W> + oln_plain_value(I, typename F::result) + apply_local(const Accumulator<F>& f, + const Image<I>& input, + const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -68,6 +73,20 @@ return output; } + template <typename F, typename I, typename W> + oln_plain_value(I, typename F::result) + apply_local_(const Accumulator<F>& f, + const Image<I>& input, + const Window<W>& win) + { + oln_plain_value(I, typename F::result) output; + prepare(output, with, input); + oln_piter(I) p(input.points()); + for_all(p) + output(p) = level::local(f, input, p, win); + return output; + } + } // end of namespace oln::level::impl @@ -81,6 +100,15 @@ return impl::apply_local_(exact(f), exact(input)); } + template <typename F, typename I, typename W> + oln_plain_value(I, typename F::result) + apply_local(const Accumulator<F>& f, + const Image<I>& input, + const Window<W>& win) + { + return impl::apply_local_(exact(f), exact(input), win); + } + # endif } // end of namespace oln::level