895: Fix : Opening, Closing, erosion, dilation.

Modification in algorithm specialization (function/set). Correction of major order errors in opening / closing. Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Fix : Opening, Closing, erosion, dilation. * oln/morpho/elementary_erosion.hh: . * oln/morpho/dilation.hh: . * oln/morpho/elementary_closing.hh: . * oln/morpho/elementary_opening.hh: . * oln/morpho/erosion.hh: . * oln/morpho/closing.hh: New. * oln/morpho/opening.hh: . * oln/level/local.hh: . level/local.hh | 46 +++++++++++++---------- morpho/closing.hh | 86 +++++++++++++++++++++++++++++++++++++++++++ morpho/dilation.hh | 25 ++++++++++++ morpho/elementary_closing.hh | 22 +++++------ morpho/elementary_erosion.hh | 5 +- morpho/elementary_opening.hh | 22 +++++------ morpho/erosion.hh | 32 ++++++++++++++-- morpho/opening.hh | 9 +--- 8 files changed, 192 insertions(+), 55 deletions(-) Index: oln/morpho/elementary_erosion.hh --- oln/morpho/elementary_erosion.hh (revision 894) +++ oln/morpho/elementary_erosion.hh (working copy) @@ -67,8 +67,9 @@ elementary_erosion_on_set_(const Image<I>&, const I&) { - oln_plain(I) tmp; - std::cerr << "morpho::impl::elementary_erosion_on_set_ is not yet impled!" << std::endl; + 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/dilation.hh --- oln/morpho/dilation.hh (revision 894) +++ oln/morpho/dilation.hh (working copy) @@ -61,8 +61,33 @@ return level::apply_local(max, input, win); } + template <typename I> + oln_plain(I) + dilation_on_set_(const Image<I>&, + const I& input) + { + border::fill(input, oln_min(oln_value(I))); + accumulator::or_<oln_value(I)> accu_or; + return level::apply_local(accu_or, input); + } + // FIXME: Add a fast version. + + // Impl facade. + + template <typename I> + oln_plain(I) dilation_(const Image<I>& input) + { + return dilation_on_function_(exact(input), exact(input)); + } + + template <typename I> + oln_plain(I) dilation_(const Binary_Image<I>& input) + { + return dilation_on_set_(exact(input), exact(input)); + } + } // end of namespace oln::morpho::impl Index: oln/morpho/elementary_closing.hh --- oln/morpho/elementary_closing.hh (revision 894) +++ oln/morpho/elementary_closing.hh (working copy) @@ -28,8 +28,6 @@ #ifndef OLN_MORPHO_ELEMENTARY_CLOSING_HH # define OLN_MORPHO_ELEMENTARY_CLOSING_HH -#include <oln/level/apply_local.hh> -#include <oln/border/fill.hh> #include <oln/morpho/elementary_erosion.hh> #include <oln/morpho/elementary_dilation.hh> @@ -41,10 +39,9 @@ // Fwd decl. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_closing(const Image<I>& input, const Window<W>& win); - + elementary_closing(const Image_with_Nbh<I>& input); # ifndef OLN_INCLUDE_ONLY @@ -53,12 +50,13 @@ // Generic version. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_closing_(const Image<I>& input, - const Window<W>& win) + elementary_closing_(const Image<I>& input); { - return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory + oln_plain(I) tmp; + tmp = elementary_dilation(input); + return elementary_erosion(tmp); } // FIXME: Add a fast version. @@ -68,11 +66,11 @@ // Facade. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_closing(const Image<I>& input, const Window<W>& win) + elementary_closing(const Image_with_Nbh<I>& input) { - return impl::elementary_closing_(exact(input), exact(win)); + return impl::elementary_closing_(exact(input)); } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_opening.hh --- oln/morpho/elementary_opening.hh (revision 894) +++ oln/morpho/elementary_opening.hh (working copy) @@ -28,8 +28,6 @@ #ifndef OLN_MORPHO_ELEMENTARY_OPENING_HH # define OLN_MORPHO_ELEMENTARY_OPENING_HH -#include <oln/level/apply_local.hh> -#include <oln/border/fill.hh> #include <oln/morpho/elementary_erosion.hh> #include <oln/morpho/elementary_dilation.hh> @@ -41,10 +39,9 @@ // Fwd decl. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_opening(const Image<I>& input, const Window<W>& win); - + elementary_opening(const Image_with_Nbh<I>& input); # ifndef OLN_INCLUDE_ONLY @@ -53,12 +50,13 @@ // Generic version. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_opening_(const Image<I>& input, - const Window<W>& win) + elementary_opening_(const Image<I>& input); { - return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory + oln_plain(I) tmp; + tmp = elementary_erosion(input); + return elementary_dilation(tmp); } // FIXME: Add a fast version. @@ -68,11 +66,11 @@ // Facade. - template <typename I, typename W> + template <typename I> oln_plain(I) - elementary_opening(const Image<I>& input, const Window<W>& win) + elementary_opening(const Image_with_Nbh<I>& input) { - return impl::elementary_opening_(exact(input), exact(win)); + return impl::elementary_opening_(exact(input)); } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/erosion.hh --- oln/morpho/erosion.hh (revision 894) +++ oln/morpho/erosion.hh (working copy) @@ -30,7 +30,7 @@ #include <oln/level/apply_local.hh> #include <oln/border/fill.hh> -#include <oln/accumulator/min.hh> +#include <oln/accumulator/max.hh> namespace oln { @@ -54,16 +54,40 @@ template <typename I, typename W> oln_plain(I) - elementary_erosion_(const Image<I>& input, - const Window<W>& win) + erosion_(const Image<I>& input, const Window<W>& win) { border::fill(input, oln_min(oln_value(I))); accumulator::min_<oln_value(I)> min; - return level::apply_local(min, input, win); + return level::apply_local(max, input, win); + } + + template <typename I> + oln_plain(I) + erosion_on_set_(const Image<I>&, + const I& input) + { + border::fill(input, oln_min(oln_value(I))); + accumulator::and_<oln_value(I)> accu_and; + return level::apply_local(accu_and, input); } // FIXME: Add a fast version. + + // Impl facade. + + template <typename I> + oln_plain(I) erosion_(const Image<I>& input) + { + return erosion_on_function_(exact(input), exact(input)); + } + + template <typename I> + oln_plain(I) erosion_(const Binary_Image<I>& input) + { + return erosion_on_set_(exact(input), exact(input)); + } + } // end of namespace oln::morpho::impl Index: oln/morpho/closing.hh --- oln/morpho/closing.hh (revision 0) +++ oln/morpho/closing.hh (revision 0) @@ -0,0 +1,86 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_MORPHO_CLOSING_HH +# define OLN_MORPHO_CLOSING_HH + +#include <oln/morpho/elementary_erosion.hh> +#include <oln/morpho/elementary_dilation.hh> + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W> + oln_plain(I) + closing(const Image<I>& input, const Window<W>& win); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W> + oln_plain(I) + closing_(const Image<I>& input, + const Window<W>& win) + { + oln_plain(I) = elementary_dilation(input, win); + return elementary_erosion(tmp, win); // FIXME : inverse(win). + } + + // FIXME: Add a fast version. + + + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W> + oln_plain(I) + closing(const Image<I>& input, const Window<W>& win) + { + return impl::closing_(exact(input), exact(win)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_CLOSING_HH Index: oln/morpho/opening.hh --- oln/morpho/opening.hh (revision 894) +++ oln/morpho/opening.hh (working copy) @@ -28,8 +28,6 @@ #ifndef OLN_MORPHO_OPENING_HH # define OLN_MORPHO_OPENING_HH -#include <oln/level/apply_local.hh> -#include <oln/border/fill.hh> #include <oln/morpho/elementary_erosion.hh> #include <oln/morpho/elementary_dilation.hh> @@ -58,9 +56,8 @@ opening_(const Image<I>& input, const Window<W>& win) { - border::fill(input, oln_min(oln_value(I))); - accumulator::max_<oln_value(I)> max; - return level::apply_local(max, input, win); + oln_plain(I) = elementary_dilation(input, win); + return elementary_erosion(tmp, win); // FIXME : inverse(win). } // FIXME: Add a fast version. @@ -84,4 +81,4 @@ } // end of namespace oln -#endif // ! OLN_MORPHO_DILATION_HH +#endif // ! OLN_MORPHO_OPENING_HH Index: oln/level/local.hh --- oln/level/local.hh (revision 894) +++ oln/level/local.hh (working copy) @@ -115,22 +115,26 @@ return f.value(); } - /* // Optimised version for OR operator with window. - template <typename A, typename I, typename W> - typename A::result - local_(const accumulator::or_<oln_value(I)>& f, + template <typename B, typename I, typename W> + B + local_(const accumulator::or_<B>& f, const Binary_Image<I>& input, const oln_point(I)& p, const Window<W>& win) { - f.init(); + f.init_with(input(p)); + if (f.value() == true) + return true; oln_qiter(W) q(p, win); for_all(q) - if (f(input(q)) == f.ultimate) - return (f.ultimate); + { + f(input(q)); + if (f.value() == true) + return true; + } return f.value(); } @@ -139,17 +143,20 @@ // Optimised version for AND operator with neighborhood. - template <typename A, typename I> - typename A::result - local_(const ::oln::accumulator::and_< oln_value(I) > f, + template <typename B, typename I> + B + local_(const accumulator::and_< B > f, const Binary_Image<I>& input, const oln_point(I)& p) { f.init_with(input(p)); oln_niter(I) n(p, input); for_all(n) - if (f(input(n)) == f.ultimate) - return (f.ultimate); + { + f(input(n)); // FIXME: Change to f.take(input(n))? + if (f.value() == true) + return true; + } return f.value(); } @@ -157,22 +164,23 @@ // Optimised version for AND operator with window. template <typename A, typename I, typename W> - typename A::result - local_(const ::oln::accumulator::and_< oln_value(I) > f, + B + local_(const accumulator::and_< B > f, const Image<I>& input, const oln_point(I)& p, const Window<W>& win) { - f.init(); + f.init_with(input(p)); oln_qiter(W) q(p, win); for_all(q) - if (f(input(q)) == f.ultimate) - return (f.ultimate); + { + f(input(q)); + if (f.value() == true) + return true; + } return f.value(); } - */ - } // end of namespace oln::level::impl
participants (1)
-
Ugo Jardonnet