929: Add local_sup/inf. Fix clone. Update Reconstruction.

Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Add local_sup/inf. Fix clone. Update Reconstruction. * oln/morpho/reconstruction.hh, * oln/morpho/cc_tarjan.hh: Updated. * oln/level/local_sup.hh: New. * oln/level/local_inf.hh: New. * oln/level/clone.hh: Fixed. level/clone.hh | 14 +-- level/local_inf.hh | 219 +++++++++++++++++++++++++++++++++++++++++++++++ level/local_sup.hh | 219 +++++++++++++++++++++++++++++++++++++++++++++++ morpho/cc_tarjan.hh | 10 +- morpho/reconstruction.hh | 70 +++++++++++---- 5 files changed, 507 insertions(+), 25 deletions(-) Index: oln/morpho/reconstruction.hh --- oln/morpho/reconstruction.hh (revision 928) +++ oln/morpho/reconstruction.hh (working copy) @@ -30,7 +30,8 @@ # include <oln/core/concept/image.hh> # include <oln/accumulator/max.hh> - +# include <oln/level/clone.hh> +# include <oln/level/fill.hh> namespace oln { @@ -38,36 +39,75 @@ namespace morpho { + template <typename I , typename J> + void + reconstruction(const Mutable_Image<I>& marker, + const Binary_Image<J>& mask); + +# ifndef OLN_INCLUDE_ONLY + namespace impl { - template <typename I , typename J> - void // FIXME : slow version. - reconstruction_(const Image_with_Nbh<I>& marker, + template <typename I> + bool + stability(const Image_with_Nbh<I>& marker, + const Image_with_Nbh<I>& tmp) + { + oln_piter(I) p(marker.points()); + for_all(p) // FIXME : Concept doesn't own .image()? add != is better + if (exact(marker).image()(p) != exact(tmp).image()(p)) + return false; + return true; + } + + template <typename I> + oln_plain(I) + reconstruction_loop(const Image_with_Nbh<I>& marker, const Binary_Image<I>& mask) { - // first - oln_fwd_piter(I) p(input.points()); - for_all(p) - marker(p) = local(max, marker, p) and mask(p); // FIXME : local_sup. + oln_plain(I) output; + prepare(output, with, marker); + accumulator::max_<oln_value(I)> max; - // second - oln_bkd_piter(I) p(input.points()); + // first pass + oln_fwd_piter(I) p(marker.points()); for_all(p) - marker(p) = local(max, marker, p) and mask(p); // FIXME : local_inf. + output(p) = local_sup(max, marker, p) and mask(p); + + // second pass + oln_bkd_piter(I) p2(marker.points()); + for_all(p2) + output(p2) = local_inf(max, marker, p2) and mask(p2); + + return output; + } + + template <typename I , typename J> + void // FIXME : Slow impl. + reconstruction_(const Image_with_Nbh<I>& marker, + const Binary_Image<J>& mask) + { + oln_plain(I) tmp = level::clone(marker); + + while ( not stability(marker, tmp) ) + { + level::fill(exact(marker).image(), exact(tmp).image()); //add fill version better. + tmp = reconstruction_loop(marker, mask); + } + + level::fill(exact(marker).image(), exact(tmp).image()); } } // end of namespace oln::morpho::impl template <typename I , typename J> void - reconstruction(const Image_with_Nbh<I>& marker, + reconstruction(const Mutable_Image<I>& marker, const Binary_Image<J>& mask) { - impl::reconstruction_(exact(mask), exact(marker)); - } - + impl::reconstruction_(exact(marker), exact(mask)); } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/cc_tarjan.hh --- oln/morpho/cc_tarjan.hh (revision 928) +++ oln/morpho/cc_tarjan.hh (working copy) @@ -29,8 +29,6 @@ # define OLN_MORPHO_CC_TARJAN_HH # include <oln/core/concept/image.hh> -# include <oln/debug/print.hh> - namespace oln { @@ -38,6 +36,12 @@ namespace morpho { + template <typename I> + oln_plain_value(I, unsigned) + cc_tarjan(const Binary_Image<I>& input); + +# ifndef OLN_INCLUDE_ONLY + namespace impl { template <typename I> @@ -134,6 +138,8 @@ return impl::cc_tarjan_(exact(input)); } +# endif // ! OLN_INCLUDE_ONLY + } // end of namespace oln::morpho } // end of namespace oln Index: oln/level/local_sup.hh --- oln/level/local_sup.hh (revision 0) +++ oln/level/local_sup.hh (revision 0) @@ -0,0 +1,219 @@ +// 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_LEVEL_LOCAL_SUP_HH +# define OLN_LEVEL_LOCAL_SUP_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/concept/window.hh> +# include <oln/core/concept/accumulator.hh> +# include <oln/accumulator/or.hh> +# include <oln/accumulator/and.hh> + +namespace oln +{ + + namespace level + { + + template <typename A, typename I> + typename A::result + local_sup(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p); + + template <typename A, typename I, typename W> + typename A::result + local_sup(const Accumulator<A>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + /// Neigborhood. + + // Generic version with neighborhood. + + template <typename A, typename I> + typename A::result + local_sup_(const A& 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) + if (n > p) + f(input(n)); + return f.value(); + } + + // Optimised version for OR operator with neighborhood. + + template <typename B, typename I> + B + local_sup_(const oln::accumulator::or_<B>& f, + const Image_with_Nbh<I>& input, + const oln_point(I)& p) + { + f.init_with(input(p)); + if (f.value() == true) + return true; + oln_niter(I) n(p, input); + for_all(n) + if (n > p) + { + f(input(n)); // FIXME: Change to f.take(input(n))? + if (f.value() == true) + return true; + } + return f.value(); + } + + // Optimised version for AND operator with neighborhood. + + template <typename B, typename I> + B + local_sup_(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) + if (n > p) + { + 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_sup_(const A& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + f.init_with(input(p)); + oln_qiter(W) q(p, win); + for_all(q) + if (q > p) + if (input.owns_(q)) + f(input(q)); + return f.value(); + } + + // Optimised version for OR operator with window. + + template <typename B, typename I, typename W> + B + local_sup_(const oln::accumulator::or_<B>& f, + const Binary_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 (q > p) + { + 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 B, typename I, typename W> + B + local_sup_(const accumulator::and_< B > f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + f.init_with(input(p)); + oln_qiter(W) q(p, win); + for_all(q) + if (q > p) + { + if (input.owns_(q)) + f(input(q)); + if (f.value() == false) + return false; + } + return f.value(); + } + + } // end of namespace oln::level::impl + + + // Facades. + + template <typename A, typename I> + typename A::result + local_sup(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p) + { + mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check(); + return impl::local_sup_(exact(f), exact(input), p); + } + + template <typename A, typename I, typename W> + typename A::result + local_sup(const Accumulator<A>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + return impl::local_sup_(exact(f), exact(input), p, exact(win)); + } + +#endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::level + +} // end of namespace oln + +#endif // ! OLN_LEVEL_LOCAL_SUP_HH Index: oln/level/local_inf.hh --- oln/level/local_inf.hh (revision 0) +++ oln/level/local_inf.hh (revision 0) @@ -0,0 +1,219 @@ +// 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_LEVEL_LOCAL_INF_HH +# define OLN_LEVEL_LOCAL_INF_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/concept/window.hh> +# include <oln/core/concept/accumulator.hh> +# include <oln/accumulator/or.hh> +# include <oln/accumulator/and.hh> + +namespace oln +{ + + namespace level + { + + template <typename A, typename I> + typename A::result + local_inf(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p); + + template <typename A, typename I, typename W> + typename A::result + local_inf(const Accumulator<A>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + /// Neigborhood. + + // Generic version with neighborhood. + + template <typename A, typename I> + typename A::result + local_inf_(const A& 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) + if (n < p) + f(input(n)); + return f.value(); + } + + // Optimised version for OR operator with neighborhood. + + template <typename B, typename I> + B + local_inf_(const oln::accumulator::or_<B>& f, + const Image_with_Nbh<I>& input, + const oln_point(I)& p) + { + f.init_with(input(p)); + if (f.value() == true) + return true; + oln_niter(I) n(p, input); + for_all(n) + if (n < p) + { + f(input(n)); // FIXME: Change to f.take(input(n))? + if (f.value() == true) + return true; + } + return f.value(); + } + + // Optimised version for AND operator with neighborhood. + + template <typename B, typename I> + B + local_inf_(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) + if (n < p) + { + 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_inf_(const A& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + f.init_with(input(p)); + oln_qiter(W) q(p, win); + for_all(q) + if (q < p) + if (input.owns_(q)) + f(input(q)); + return f.value(); + } + + // Optimised version for OR operator with window. + + template <typename B, typename I, typename W> + B + local_inf_(const oln::accumulator::or_<B>& f, + const Binary_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 (q < p) + { + 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 B, typename I, typename W> + B + local_inf_(const accumulator::and_< B > f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + f.init_with(input(p)); + oln_qiter(W) q(p, win); + for_all(q) + if (q < p) + { + if (input.owns_(q)) + f(input(q)); + if (f.value() == false) + return false; + } + return f.value(); + } + + } // end of namespace oln::level::impl + + + // Facades. + + template <typename A, typename I> + typename A::result + local_inf(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p) + { + mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check(); + return impl::local_inf_(exact(f), exact(input), p); + } + + template <typename A, typename I, typename W> + typename A::result + local_inf(const Accumulator<A>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + return impl::local_inf_(exact(f), exact(input), p, exact(win)); + } + +#endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::level + +} // end of namespace oln + +#endif // ! OLN_LEVEL_LOCAL_INF_HH Index: oln/level/clone.hh --- oln/level/clone.hh (revision 928) +++ oln/level/clone.hh (working copy) @@ -29,9 +29,7 @@ #ifndef OLN_LEVEL_CLONE_HH # define OLN_LEVEL_CLONE_HH -# include <oln/core/abstract/image.hh> -# include <oln/core/abstract/iterator.hh> - +# include <oln/core/concept/image.hh> namespace oln { @@ -41,7 +39,7 @@ /// Fwd decl. template <typename I> - oln_plain(I) clone(const abstract::image<I>& input); + oln_plain(I) clone(const Image<I>& input); # ifndef OLN_INCLUDE_ONLY @@ -51,10 +49,10 @@ /// Generic version. template <typename I> - oln_plain(I) clone(const abstract::image<I>& input) + oln_plain(I) clone(const Image<I>& input) { - oln_plain(I) output(input.topo()); - oln_piter(I) p(input.topo()); + oln_plain(I) output(input.points()); + oln_piter(I) p(input.points()); for_all(p) output(p) = input(p); return output; @@ -65,7 +63,7 @@ /// Facade. template <typename I> - oln_plain(I) clone(const abstract::image<I>& input) + oln_plain(I) clone(const Image<I>& input) { return impl::clone(input); }
participants (1)
-
Ugo Jardonnet