proto-1.0 172: Morpho is (partially) back.

2005-04-27 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> * oln/morpho/closing.hh: New-like file. * oln/morpho/dilation.hh: Likewise. * oln/morpho/elementary_erosion.hh: Likewise. * oln/morpho/erosion.hh: Likewise. * oln/morpho/geodesic_erosion.hh: Likewise. * oln/morpho/opening.hh: Likewise. * oln/morpho/stat.hh: Likewise. * oln/morpho/tags.hh: Likewise. Index: oln/morpho/closing.hh =================================================================== --- oln/morpho/closing.hh (revision 0) +++ oln/morpho/closing.hh (revision 0) @@ -0,0 +1,103 @@ +// Copyright (C) 2001-2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_CLOSING_HH +# define OLENA_MORPHO_CLOSING_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/morpho/erosion.hh> +# include <oln/morpho/dilation.hh> + + +namespace oln { + + namespace morpho { + + + + // fwd decl of facade + + template<typename I, typename W> + oln_type_of(I, concrete) closing(const abstract::image<I>& input, + const abstract::window<W>& win); + + + + namespace impl { + + + + // generic + + template<typename I, typename W> + oln_type_of(I, concrete) closing_(const abstract::image<I>& input, + const abstract::window<W>& win) + { + entering("generic"); + oln_type_of(I, concrete) output; + + output = dilation(erosion(input, win), -win); + + exiting("generic"); + return output; + } + + + + } // end of namespace oln::morpho::impl + + + + + /// Generic closing (facade). + + template<typename I, typename W> + oln_type_of(I, concrete) closing(const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + entering("morpho::closing"); + oln_type_of(I, concrete) output; + + output = impl::closing_(input.exact(), win.exact()); + + exiting("morpho::closing"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_CLOSING_HH Index: oln/morpho/tags.hh =================================================================== --- oln/morpho/tags.hh (revision 0) +++ oln/morpho/tags.hh (revision 0) @@ -0,0 +1,152 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_TAGS_HH +# define OLENA_MORPHO_TAGS_HH + +# include <mlc/any.hh> +# include <mlc/cmp.hh> +# include <oln/basics.hh> + +# include <oln/morpho/stat.hh> // FIXME: rename!!! + + + +namespace oln { + + namespace morpho { + + + namespace tag + { + + // Tags for selecting a given 'morphology' due to + // the couple of dual operations performed in erosion + // and dilation. + + + template <typename K> + struct kind : public mlc::any<K> // FIXME: name! + { + + // min value in input on a window centered at p + template <typename I, typename W> + oln_type_of(I, value) + min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) const + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + return this->exact().impl_min(input, p, win); + } + + // max value in input on a window centered at p + template <typename I, typename W> + oln_type_of(I, value) + max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) const + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + return this->exact().impl_max(input, p, win); + } + + // min value in input of neighborhoods of p + template <typename I> + oln_type_of(I, value) + min_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) const + { + return this->exact().impl_min_nbh(input, p); + } + + }; + + + + struct classical_type : public kind< classical_type > + { + // min value in input on a window centered at p + template <typename I, typename W> + oln_type_of(I, value) + impl_min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) const + { + return morpho::local_min(input, p, win); + } + + // max value in input on a window centered at p + template <typename I, typename W> + oln_type_of(I, value) + impl_max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) const + { + return morpho::local_max(input, p, win); + } + + // min value in input of neighborhoods of p + template <typename I> + oln_type_of(I, value) + impl_min_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) const + { + return morpho::local_min_nbh(input, p); + } + + }; + + const classical_type classical = classical_type(); + + + // Tags for approaches in reconstructions. + + template <typename Op> struct oper {}; + + struct by_dilation_type : public oper< by_dilation_type > {}; + struct by_erosion_type : public oper< by_erosion_type > {}; + + + // Tags for common canvas. + + template <typename A> struct algo {}; + + struct sequential_type : public algo< sequential_type > {}; + struct hybrid_type : public algo< hybrid_type > {}; + struct parallel_type : public algo< parallel_type > {}; + struct unionfind_type : public algo< unionfind_type > {}; + + } // end of namespace oln::morpho::tag + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_EROSION_HH Index: oln/morpho/opening.hh =================================================================== --- oln/morpho/opening.hh (revision 0) +++ oln/morpho/opening.hh (revision 0) @@ -0,0 +1,118 @@ +// Copyright (C) 2001-2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_OPENING_HH +# define OLENA_MORPHO_OPENING_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/morpho/erosion.hh> +# include <oln/morpho/dilation.hh> + + +namespace oln { + + namespace morpho { + + + + // Fwd decl of opening's facade. + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) opening(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win); + + // Facade for classical opening. + + template<typename I, typename W> + oln_type_of(I, concrete) opening(const abstract::image<I>& input, + const abstract::window<W>& win) + { + return opening(tag::classical, input, win); + } + + + + namespace impl { + + + // generic + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) opening_(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + entering("->generic"); + registering(input, "input"); + + oln_type_of(I, concrete) output("output"); + output = dilation(kind, erosion(kind, input, win), -win); + + exiting("->generic"); + return output; + } + + + // add some other impls here... + + + } // end of namespace oln::morpho::impl + + + + + /// Generic opening (facade). + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) opening(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + entering("morpho::opening"); + registering(input, "input"); + + oln_type_of(I, concrete) output("output"); + output = impl::opening_(kind, input.exact(), win.exact()); + + exiting("morpho::opening"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_OPENING_HH Index: oln/morpho/elementary_erosion.hh =================================================================== --- oln/morpho/elementary_erosion.hh (revision 0) +++ oln/morpho/elementary_erosion.hh (revision 0) @@ -0,0 +1,113 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_ELEMENTARY_EROSION_HH +# define OLENA_MORPHO_ELEMENTARY_EROSION_HH + +# include <oln/utils/record.hh> +# include <oln/core/gen/image_with_nbh.hh> +# include <oln/morpho/tags.hh> + + +namespace oln { + + namespace morpho { + + + + // Fwd decl of elementary erosion's facade. + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_erosion(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input); + + // Facade for classical elementary erosion. + + template<typename I> + oln_type_of(I, concrete) elementary_erosion(const abstract::image_with_nbh<I>& input) + { + return elementary_erosion(tag::classical, input); + } + + + + namespace impl { + + + // generic + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_erosion_(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input) + { + entering("->generic"); + registering(input, "input"); + + oln_type_of(I, concrete) output(input.size(), "output"); + + oln_type_of(I, piter) p(input.size()); + for_all_p (p) + output[p] = kind.min_nbh(input, p); + + exiting("->generic"); + return output; + } + + + // add some other impls here... + + + } // end of namespace oln::morpho::impl + + + + + /// Generic elementary_erosion (facade). + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_erosion(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input) + { + entering("morpho::elementary_erosion"); + registering(input, "input"); + + oln_type_of(I, concrete) output("output"); + output = impl::elementary_erosion_(kind, input.exact()); + + exiting("morpho::elementary_erosion"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_ELEMENTARY_EROSION_HH Index: oln/morpho/dilation.hh =================================================================== --- oln/morpho/dilation.hh (revision 0) +++ oln/morpho/dilation.hh (revision 0) @@ -0,0 +1,143 @@ +// Copyright (C) 2001-2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_DILATION_HH +# define OLENA_MORPHO_DILATION_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/utils/record.hh> +# include <oln/basics.hh> +# include <oln/core/2d/window2d.hh> +# include <oln/morpho/tags.hh> + + +namespace oln { + + namespace morpho { + + + + // Fwd decl of dilation's facade. + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) dilation(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win); + + // Facade for classical dilation. + + template<typename I, typename W> + oln_type_of(I, concrete) dilation(const abstract::image<I>& input, + const abstract::window<W>& win) + { + return dilation(tag::classical, input, win); + } + + + namespace impl { + + // generic + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) dilation_(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + entering("->generic"); + registering(input, "input"); + + oln_type_of(I, concrete) output(input.size(), "output"); + + oln_type_of(I, fwd_piter) p(input.size()); + for_all_p (p) + output[p] = kind.min(input, p, win); + + exiting("->generic"); + return output; + } + + + + // win is a 2D rectangle + + template<typename K, typename I> + oln_type_of(I, concrete) dilation_(const tag::kind<K>& kind, + const abstract::image2d<I>& input, + const win_rectangle2d& win) + { + entering("->(image2d,win_rectangle2d)"); + registering(input, "input"); + + oln_type_of(I, concrete) temp("temp"), output("output"); + + win_hline2d hline(win.width); // FIXME: Cf. Soille, use L(i,dp) + win_vline2d vline(win.height); + + temp = dilation(kind, input, hline); + output = dilation(kind, temp, vline); + + exiting("->(image2d,win_rectangle2d)"); + return output; + } + + + // add some other impls here... + + + } // end of namespace oln::morpho::impl + + + + + /// Generic dilation (facade). + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) dilation(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + entering("morpho::dilation"); + + oln_type_of(I, concrete) output("output"); + output = impl::dilation_(kind, input.exact(), win.exact()); + + exiting("morpho::dilation"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_DILATION_HH Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 0) +++ oln/morpho/stat.hh (revision 0) @@ -0,0 +1,136 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_STAT_HH +# define OLENA_MORPHO_STAT_HH + +# include <mlc/cmp.hh> +# include <ntg/bin.hh> +# include <oln/basics.hh> +# include <oln/funobj/accum.hh> + + +namespace oln { + + namespace morpho { + + + /// Local min on a function. + + template <typename I, typename W> + oln_type_of(I, value) local_min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + funobj::min_accumulator<oln_type_of(I, value)> minval; + + for_all_q_of_p (q, p) + if (input.hold(q)) + minval(input[q]); + + return minval; + } + + + template <typename I> + oln_type_of(I, value) local_min_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) + { + oln_type_of(I, niter) n(input); + funobj::min_accumulator_init<oln_type_of(I, value)> minval(input[p]); + + for_all_n_of_p (n, p) + if (input.hold(n)) + minval(input[n]); + + return minval; + } + + + /// Local min on a set. + + template <typename I, typename W> + bool local_min(const abstract::binary_image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q) and not input[q]) + return false; + return true; + } + + + /// Local max on a function. + + template <typename I, typename W> + oln_type_of(I, value) local_max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + funobj::max_accumulator<oln_type_of(I, value)> maxval; + + for_all_q_of_p (q, p) + if (input.hold(q)) + maxval(input[q]); + + return maxval; + } + + + /// Local max on a set. + + template <typename I, typename W> + bool local_max(const abstract::binary_image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q) and input[q]) + return true; + return false; + } + + + } // end of namespace morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_STAT_HH Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 0) +++ oln/morpho/erosion.hh (revision 0) @@ -0,0 +1,143 @@ +// Copyright (C) 2001-2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_EROSION_HH +# define OLENA_MORPHO_EROSION_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/utils/record.hh> +# include <oln/basics.hh> +# include <oln/core/2d/window2d.hh> +# include <oln/morpho/tags.hh> + + +namespace oln { + + namespace morpho { + + + + // Fwd decl of erosion's facade. + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) erosion(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win); + + // Facade for classical erosion. + + template<typename I, typename W> + oln_type_of(I, concrete) erosion(const abstract::image<I>& input, + const abstract::window<W>& win) + { + return erosion(tag::classical, input, win); + } + + + namespace impl { + + // generic + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) erosion_(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + entering("->generic"); + registering(input, "input"); + + oln_type_of(I, concrete) output(input.size(), "output"); + + oln_type_of(I, fwd_piter) p(input.size()); + for_all_p (p) + output[p] = kind.min(input, p, win); + + exiting("->generic"); + return output; + } + + + + // win is a 2D rectangle + + template<typename K, typename I> + oln_type_of(I, concrete) erosion_(const tag::kind<K>& kind, + const abstract::image2d<I>& input, + const win_rectangle2d& win) + { + entering("->(image2d,win_rectangle2d)"); + registering(input, "input"); + + oln_type_of(I, concrete) temp("temp"), output("output"); + + win_hline2d hline(win.width); // FIXME: Cf. Soille, use L(i,dp) + win_vline2d vline(win.height); + + temp = erosion(kind, input, hline); + output = erosion(kind, temp, vline); + + exiting("->(image2d,win_rectangle2d)"); + return output; + } + + + // add some other impls here... + + + } // end of namespace oln::morpho::impl + + + + + /// Generic erosion (facade). + + template<typename K, typename I, typename W> + oln_type_of(I, concrete) erosion(const tag::kind<K>& kind, + const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + entering("morpho::erosion"); + + oln_type_of(I, concrete) output("output"); + output = impl::erosion_(kind, input.exact(), win.exact()); + + exiting("morpho::erosion"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_EROSION_HH Index: oln/morpho/geodesic_erosion.hh =================================================================== --- oln/morpho/geodesic_erosion.hh (revision 0) +++ oln/morpho/geodesic_erosion.hh (revision 0) @@ -0,0 +1,112 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_GEODESIC_EROSION_HH +# define OLENA_MORPHO_GEODESIC_EROSION_HH + +# include <mlc/cmp.hh> +# include <mlc/contract.hh> + +# include <oln/utils/record.hh> +# include <oln/core/pw/all.hh> +# include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?) +# include <oln/morpho/elementary_erosion.hh> + + + +// FIXME: such routines should be written somewhere else... + +template <typename L, typename R> +bool operator >= (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::p_value(lhs) >= oln::p_value(rhs)); +} + + + +namespace oln { + + namespace morpho { + + + + /// Generic geodesic erosion. + + template<typename K, typename I, typename II> + oln_type_of(I, concrete) geodesic_erosion(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& marker, + const abstract::image<II>& mask) + { + // FIXME: later, test the short code: + // FIXME: return max(elementary_erosion(kind, marker), mask) + + // FIXME: and even later: + // FIXME: return elementary_erosion(kind, marker) _max_ mask + + mlc::eq<oln_type_of(I, grid), oln_type_of(II, grid)>::ensure(); + + entering("morpho::geodesic_erosion"); + + registering(marker, "marker"); + registering(mask, "mask"); + precondition(marker.size() == mask.size() + and marker >= mask); + + oln_type_of(I, concrete) + ero("ero"), + output(marker.size(), "output"); + + ero = elementary_erosion(kind, marker); + + // FIXME: replace code below by a pw::max... + oln_type_of(I, fwd_piter) p(marker.size()); + for_all_p (p) + output[p] = std::max(ero[p].value(), mask[p].value()); + + exiting("morpho::geodesic_erosion"); + return output; + } + + + /// Generic classical geodesic erosion. + + template<typename I, typename II> + oln_type_of(I, concrete) geodesic_erosion(const abstract::image_with_nbh<I>& marker, + const abstract::image<II>& mask) + { + return geodesic_erosion(tag::classical, marker, mask); + } + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_GEODESIC_EROSION_HH
participants (1)
-
Thierry GERAUD