---
swilena/ChangeLog | 4 ++++
swilena/box2d.i | 23 ++++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/swilena/ChangeLog b/swilena/ChangeLog
index 391d3e3..917269e 100644
--- a/swilena/ChangeLog
+++ b/swilena/ChangeLog
@@ -1,5 +1,9 @@
2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+ * box2d.i: Add a ctor taking two `int's as argument.
+
+2009-05-26 Roland Levillain <roland(a)lrde.epita.fr>
+
* python/sps-local.in (PYTHONPATH): Fix paths.
2009-05-14 Roland Levillain <roland(a)lrde.epita.fr>
diff --git a/swilena/box2d.i b/swilena/box2d.i
index 00e91e1..e24f016 100644
--- a/swilena/box2d.i
+++ b/swilena/box2d.i
@@ -1,5 +1,5 @@
// -*- C++ -*-
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -42,8 +42,11 @@
%include "mln/core/site_set/box.hh";
%include "mln/core/alias/box2d.hh";
-// Swig tries to wrap everything by default; prevent it from wrapping
-// invalid methods (1D and 3D ctors for a box2d).
+/* Swig tries to wrap everything by default; prevent it from wrapping
+ invalid methods (1D and 3D ctors for an mln::box2d). Moreover, as
+ Python does not automatically convert `int's to `short's, we cannot
+ use the ctor taking two `mln::def::coord's (i.e. `short's)
+ either. */
/* FIXME: Can't we simplify these directives, i.e. use `point2d'
directly? Maybe we could use mln_coord()? */
%ignore mln::box< mln::point<mln::grid::square, mln::def::coord> >
@@ -51,11 +54,22 @@
%ignore mln::box< mln::point<mln::grid::square, mln::def::coord> >
::box(typename mln::point<mln::grid::square, mln::def::coord>::coord,
+ typename mln::point<mln::grid::square, mln::def::coord>::coord);
+
+%ignore mln::box< mln::point<mln::grid::square, mln::def::coord> >
+::box(typename mln::point<mln::grid::square, mln::def::coord>::coord,
typename mln::point<mln::grid::square, mln::def::coord>::coord,
typename mln::point<mln::grid::square, mln::def::coord>::coord);
-%extend mln::box
+%extend mln::box< mln::point<mln::grid::square, mln::def::coord> >
{
+ // Provide a ctor creating an `mln::box2d' from two `int's.
+ mln::box< mln::point< mln::grid::square, mln::def::coord> > (int nrows,
+ int ncols)
+ {
+ return new mln::box<mln::point2d>(nrows, ncols);
+ }
+
unsigned nrows() const
{
// FIXME: This is the exact content of box_impl_<2, C, E>::nrows.
@@ -69,5 +83,4 @@
}
}
-
%template(box2d) mln::box< mln::point<mln::grid::square, mln::def::coord> >;
--
1.6.1.2
On 26/05/09 20:03, Roland Levillain wrote:
> Vincent Ordy<ordy(a)lrde.epita.fr> writes:
>> inim: Improve boxes algorithm.
>> Because of recent changes in scribo, the current work won't compile
>> with the last SVN revision. However, it used to compile with r3697.
>
> Ce n'est pas le genre d'information qui doit figurer dans un ChangeLog.
> Ce fichier décrit ce qui se passe dans la distribution des fichiers, pas
> dans le dépôt.
Noté.
>> * boxes.cc: Fix a couple of bugs.
>
> Mauvais chemin.
>
> Attention aux bugs de svn-wrapper : il faut faire `svn commit' depuis le
> répertoire qui contient le ChangeLog où seront inscrits les changements
> (en l'occurrence milena/sandbox/).
Arf, c'est de ma faute, je n'y ai pas prêté attention à ce moment.
--
Warren Seine
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-05-26 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Move propagation and filtering attributes routines from sandbox.
* mln/morpho/tree/filter: New.
* mln/morpho/tree/propagate_if.hh: New.
* mln/morpho/tree/propagate_node.hh: New.
* mln/morpho/tree/propagate_representative.hh: New.
* sandbox/edwin/mln/morpho/tree/filter/all.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/direct.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/max.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/min.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/subtractive.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_if.hh: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_node.hh: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_representative.hh: Remove.
---
trunk/milena/headers.mk | 10
trunk/milena/mln/morpho/tree/filter/all.hh | 66 +++
trunk/milena/mln/morpho/tree/filter/direct.hh | 91 ++++
trunk/milena/mln/morpho/tree/filter/max.hh | 110 +++++
trunk/milena/mln/morpho/tree/filter/min.hh | 100 ++++
trunk/milena/mln/morpho/tree/filter/subtractive.hh | 97 ++++
trunk/milena/mln/morpho/tree/propagate_if.hh | 326 +++++++++++++++
trunk/milena/mln/morpho/tree/propagate_node.hh | 209 +++++++++
trunk/milena/mln/morpho/tree/propagate_representative.hh | 76 +++
9 files changed, 1084 insertions(+), 1 deletion(-)
Index: trunk/milena/headers.mk
===================================================================
--- trunk/milena/headers.mk (revision 3874)
+++ trunk/milena/headers.mk (revision 3875)
@@ -261,6 +261,8 @@
mln/core/image/complex_window_piter.hh \
mln/core/image/complex_windows.hh \
mln/core/image/decorated_image.hh \
+mln/core/image/dmorph/all.hh \
+mln/core/image/dmorph/transformed_image.hh \
mln/core/image/edge_image.hh \
mln/core/image/essential.hh \
mln/core/image/extended.hh \
@@ -398,6 +400,8 @@
mln/core/site_set/p_run_piter.hh \
mln/core/site_set/p_set.hh \
mln/core/site_set/p_set_of.hh \
+mln/core/site_set/p_transformed.hh \
+mln/core/site_set/p_transformed_piter.hh \
mln/core/site_set/p_vaccess.hh \
mln/core/site_set/p_vertices.hh \
mln/core/site_set/p_vertices_psite.hh \
@@ -664,6 +668,8 @@
mln/io/pgm/all.hh \
mln/io/pgm/load.hh \
mln/io/pgm/save.hh \
+mln/io/plot/all.hh \
+mln/io/plot/load.hh \
mln/io/plot/save.hh \
mln/io/pnm/all.hh \
mln/io/pnm/load_header.hh \
@@ -677,7 +683,6 @@
mln/io/ppm/save.hh \
mln/io/tiff/all.hh \
mln/io/tiff/load.hh \
-mln/io/tiff/save.hh \
mln/io/txt/all.hh \
mln/io/txt/save.hh \
mln/labeling/all.hh \
@@ -934,6 +939,8 @@
mln/morpho/reconstruction/all.hh \
mln/morpho/reconstruction/by_dilation/all.hh \
mln/morpho/reconstruction/by_dilation/union_find.hh \
+mln/morpho/reconstruction/by_erosion/all.hh \
+mln/morpho/reconstruction/by_erosion/union_find.hh \
mln/morpho/skeleton_constrained.hh \
mln/morpho/thickening.hh \
mln/morpho/thick_miss.hh \
@@ -1245,6 +1252,7 @@
mln/value/stack.hh \
mln/value/super_value.hh \
mln/value/viter.hh \
+mln/version.hh \
mln/win/all.hh \
mln/win/backdiag2d.hh \
mln/win/ball.hh \
Index: trunk/milena/mln/morpho/tree/propagate_representative.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_representative.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_representative.hh (revision 3875)
@@ -0,0 +1,76 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_
+
+/// \file mln/morpho/tree/propagate_representative.hh
+///
+/// Component tree routines.
+
+namespace mln{
+ namespace morpho {
+ namespace tree {
+
+ /**
+ ** Propagate the representative node's value to
+ ** non-representative points of the component.
+ **
+ ** @param t Component tree.
+ ** @param f_ Value image.
+ */
+ template <typename T, typename F>
+ void
+ propagate_representative(const T& t, Image<F>& f_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F>
+ inline
+ void
+ propagate_representative(const T& t, Image<F>& f_)
+ {
+ F a = exact(f_);
+ mln_up_site_piter(T) p(t);
+ for_all(p)
+ if (! t.is_a_node(p))
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p));
+ }
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ }
+ }
+}
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_representative.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/filter/min.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/min.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/min.hh (revision 3875)
@@ -0,0 +1,100 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_MIN_HH_
+# define MLN_MORPHO_TREE_FILTER_MIN_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+
+/**
+** @file mln/morpho/tree/filter/min.hh
+**
+** @brief Filtering with min strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+
+ /**
+ ** Min pruning strategy. A node is removed iif its parent is
+ ** removed or if it does not verify the predicate \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::min");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)) || !pred(n))
+ {
+ f(n) = f(tree.parent(n));
+ mark(n) = true;
+ }
+
+ trace::exiting("mln::morpho::tree::filter::min");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MIN_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/max.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/max.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/max.hh (revision 3875)
@@ -0,0 +1,110 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_MAX_HH_
+# define MLN_MORPHO_TREE_FILTER_MAX_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/max.hh
+**
+** @brief Filtering with max strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Max pruning strategy. A node is removed iif all of its
+ ** children are removed or if it does not verify the predicate
+ ** \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::max");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, true);
+
+ {
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!mark(n))
+ mark(tree.parent(n)) = false;
+ else if (pred(n))
+ {
+ mark(tree.parent(n)) = false;
+ mark(n) = false;
+ }
+ }
+
+ {
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(n))
+ f(n) = f(tree.parent(n));
+ }
+
+ trace::exiting("mln::morpho::tree::filter::max");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MAX_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/all.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/all.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/all.hh (revision 3875)
@@ -0,0 +1,66 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_ALL_HH_
+# define MLN_MORPHO_TREE_FILTER_ALL_HH_
+
+/**
+** @file mln/morpho/tree/filter.hh
+**
+** Methods to handle component tree filtering strategies with
+** non-increasing attribute. Nevertheless, it works on increasing
+** predicate as well. In this case, all strategies have the same
+** result but min filter or direct filter should be used in term
+** of performance. If a predicate test is too slow, then consider
+** the min filter that minimizes calls to predicate function.
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ /// Namespace for attribute filtering.
+ namespace filter {
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+
+// Pruning strategies.
+# include <mln/morpho/tree/filter/min.hh>
+# include <mln/morpho/tree/filter/max.hh>
+
+// Non-pruning stategies.
+# include <mln/morpho/tree/filter/direct.hh>
+# include <mln/morpho/tree/filter/subtractive.hh>
+
+
+
+#endif /* !MLN_MORPHO_TREE_FILTER_ALL_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/direct.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/direct.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/direct.hh (revision 3875)
@@ -0,0 +1,91 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_DIRECT_HH_
+# define MLN_MORPHO_TREE_FILTER_DIRECT_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/direct.hh
+**
+** @brief Filtering with direct strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Direct non-pruning strategy. A node is removed if it does
+ ** not verify the predicate. The sub-components remain intact.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::direct");
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::direct");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_DIRECT_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/subtractive.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/subtractive.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/subtractive.hh (revision 3875)
@@ -0,0 +1,97 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_
+# define MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/fun/ops.hh>
+
+# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_if.hh>
+
+/**
+** @file mln/morpho/tree/filter/subtractive.hh
+**
+** @brief Filtering with subtractive strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Subtractive pruning strategy. The node is removed if it
+ ** does not verify the predicate. The sub-components values
+ ** are set to the value of the removed component.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::subtractive");
+
+ morpho::tree::propagate_if(tree, f, morpho::tree::desc_propagation (), !pred);
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::subtractive");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/filter
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/propagate_node.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_node.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_node.hh (revision 3875)
@@ -0,0 +1,209 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_PROPAGATE_NODE_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_NODE_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/macros.hh>
+# include <mln/morpho/tree/data.hh>
+
+/// \file mln/morpho/tree/propagate_node.hh
+///
+/// Functions to propagate node in the tree.
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ /**
+ ** Propagate a value \p v from a node \p n to its descendants.
+ **
+ ** @param n[in] Node to propagate.
+ ** @param t[in] Component tree used for propagation.
+ ** @param a_[in] Attribute image where values are propagated.
+ ** @param v[in] Value to propagate.
+ ** @param nb_leaves[out] Optional. Store the number of leaves in
+ ** the component.
+ */
+ template <typename T, typename A>
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v,
+ unsigned* nb_leaves = 0);
+
+ /**
+ ** Propagate the node's value to its descendants.
+ **
+ ** @param n[in] Node to propagate.
+ ** @param t[in] Component tree used for propagation.
+ ** @param a_[in] Attribute image where values are propagated.
+ ** @param nb_leaves[out] Optional. Store the number of leaves in
+ ** the component.
+ */
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A)& n,
+ const T& t,
+ Image<A>& a_,
+ unsigned* nb_leaves = 0);
+
+
+ /**
+ ** Propagate a value \p v from a node \p n to its ancestors.
+ **
+ ** @param n Node to propagate.
+ ** @param t Component tree used for propagation.
+ ** @param a_ Attribute image where values are propagated.
+ ** @param v Value to propagate.
+ */
+ template <typename T, typename A>
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v);
+
+ /**
+ ** Propagate the node's value to its ancestors.
+ **
+ ** @param n Node to propagate.
+ ** @param t Component tree used for propagation.
+ ** @param a_ Attribute image where values are propagated.
+ */
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_);
+
+
+ # ifndef MLN_INCLUDE_ONLY
+
+ /* Descendants propagation */
+
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v,
+ unsigned* nb_leaves = 0)
+ {
+ A& a = exact(a_);
+ mln_precondition(a.is_valid());
+ mln_precondition(a.domain() == t.f().domain());
+ mln_precondition(a.domain().has(n));
+
+
+ if (!t.is_a_node(n)) // Get the representant.
+ n = t.parent(n);
+ mln_assertion(t.is_a_node(n));
+
+ typename T::preorder_piter pp(t, n);
+
+ pp.start(); // We don't set n to v.
+
+ if (nb_leaves)
+ *nb_leaves += t.is_a_leaf(pp);
+
+ for (pp.next(); pp.is_valid(); pp.next())
+ {
+ a(pp) = v;
+ if (nb_leaves && t.is_a_leaf(pp))
+ ++(*nb_leaves);
+ }
+ }
+
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ unsigned* nb_leaves = 0)
+
+ {
+ A& a = exact(a_);
+ propagate_node_to_descendants(n, t, a, a(n), nb_leaves);
+ }
+
+
+ /* Ancestors propagation */
+
+ template <typename T, typename A>
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ mln_precondition(a.is_valid());
+ mln_precondition(a.domain() == t.f().domain());
+ mln_precondition(a.domain().has(n));
+
+ if (!t.is_a_node(n)) // Get the representant.
+ n = t.parent(n);
+ mln_assertion(t.is_a_node(n));
+
+ if (t.is_root(n))
+ return;
+
+ do {
+ n = t.parent(n);
+ a(n) = v;
+ } while (!t.is_root(n));
+
+ }
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_)
+ {
+ A& a = exact(a_);
+ propagate_node_to_ancestors(n, t, a, a(n));
+ }
+
+ # endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_NODE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_node.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/propagate_if.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_if.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_if.hh (revision 3875)
@@ -0,0 +1,326 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_PROPAGATE_IF_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_IF_HH_
+
+/**
+** @file mln/morpho/tree/propagate_if.hh
+**
+** @brief Routines to handle propagation with predicate.
+**
+*/
+
+# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_node.hh>
+
+# include <mln/data/fill.hh>
+# include <mln/pw/all.hh>
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ template <typename WP>
+ struct way_of_propagation : Object< WP > { protected: way_of_propagation() {}; };
+ struct desc_propagation : way_of_propagation <desc_propagation> {};
+ struct asc_propagation : way_of_propagation <asc_propagation> {};
+
+ /**
+ ** Propagate nodes checking the predicate \p pred in the way
+ ** defined by \p way_of_propagation.
+ **
+ ** @param tree Component tree used for propagation.
+ ** @param a_ Attributed image where values are propagated.
+ ** @param way_of_propagation Propagate node in acsendant or
+ ** descendant way.
+ ** @param pred Predicate that node must check to be propagated.
+ ** @param v Value to be propagated. (By default \p v is the value
+ ** at the node being propagated).
+ */
+ template <typename T, typename A, typename P2B, typename WP>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const Function_p2b<P2B>& pred,
+ const mln_value(A)& v);
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const desc_propagation&,
+ const Function_p2b<P2B>& pred);
+
+ /**
+ ** Propagate nodes having the value v in the way
+ ** defined by \p way_of_propagation.
+ **
+ ** @param tree Component tree used for propagation.
+ ** @param a_ Attributed image where values are propagated.
+ ** @param way_of_propagation Propagate node in acsendant or
+ ** descendant way.
+ ** @param v Value that node must have to be propagated.
+ ** @param v_prop Value to propagate (By default it is the value
+ ** at the node being propagated).
+ */
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const mln_value(A)& v,
+ const mln_value(A)& v_prop);
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const mln_value(A)& v);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const asc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (pred(n) && a(t.parent(n)) != v)
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const desc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (a(n) != v && pred(t.parent(n)))
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const desc_propagation& prop,
+ const P2B& pred)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (a(n) != a(t.parent(n)) && pred(t.parent(n)))
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const desc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)))
+ {
+ a(n) = v;
+ mark(n) = true;
+ }
+ else if (pred(n))
+ mark(n) = true;
+ mln_postcondition(check_propagate_if(tree, a, prop, pred, v));
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const desc_propagation& prop,
+ const P2B& pred)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)))
+ {
+ a(n) = a(tree.parent(n));
+ mark(n) = true;
+ }
+ else if (pred(n))
+ mark(n) = true;
+ mln_postcondition(check_propagate_if(tree, a, prop, pred));
+ }
+
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const asc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(n))
+ {
+ a(n) = v;
+ mark(tree.parent(n)) = true;
+ }
+ else if (pred(n))
+ mark(tree.parent(n)) = true;
+
+ mln_postcondition(check_propagate_if(tree, a, prop, pred, v));
+ }
+
+ } // end of namespace mln::morpho::tree::internal
+
+
+ /* Facades */
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const mln_value(A)& v,
+ const mln_value(A)& v_prop)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+
+ internal::propagate_if(tree, a, prop, pw::value(a) == pw::cst(v), v_prop);
+ }
+
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+
+ internal::propagate_if(tree, a, prop, pw::value(a) == pw::cst(v), v);
+ }
+
+ template <typename T, typename A, typename P2B, typename WP>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const Function_p2b<P2B>& pred_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+ const P2B& pred = exact(pred_);
+
+ internal::propagate_if(tree, a, prop, pred, v);
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const desc_propagation& prop,
+ const Function_p2b<P2B>& pred_)
+ {
+ A& a = exact(a_);
+ const P2B& pred = exact(pred_);
+
+ internal::propagate_if(tree, a, prop, pred);
+ }
+
+#endif /* !MLN_INCLUDE_ONLY */
+
+
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_IF_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_if.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_representative.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_node.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_if.hh (deleted)
===================================================================
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-26 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Check guard and separate attribute filters into their own file.
* edwin/mln/morpho/tree/filter.hh,
* edwin/mln/morpho/tree/filter/all.hh,
* edwin/mln/morpho/tree/filter/direct.hh,
* edwin/mln/morpho/tree/filter/max.hh,
* edwin/mln/morpho/tree/filter/min.hh,
* edwin/mln/morpho/tree/filter/subtractive.hh,
* edwin/mln/morpho/tree/filter:
Attribute filtering routines.
* edwin/mln/morpho/tree/propagate_representative.hh,
* edwin/mln/morpho/tree/propagate_if.hh,
* edwin/mln/morpho/tree/propagate_node.hh:
Basic propagation routines.
* edwin/rush/exo2/wst_from_tree.cc,
* edwin/tests/sharp.cc:
Fix WST on the reconstructed by erosion image.
---
mln/morpho/tree/filter.hh | 148 ----------------------------
mln/morpho/tree/filter/all.hh | 66 ++++++++++++
mln/morpho/tree/filter/direct.hh | 91 +++++++++++++++++
mln/morpho/tree/filter/max.hh | 110 ++++++++++++++++++++
mln/morpho/tree/filter/min.hh | 100 ++++++++++++++++++
mln/morpho/tree/filter/subtractive.hh | 97 ++++++++++++++++++
mln/morpho/tree/propagate.hh | 63 ++++++++---
mln/morpho/tree/propagate_if.hh | 5
mln/morpho/tree/propagate_node.hh | 4
mln/morpho/tree/propagate_representative.hh | 76 ++++++++++++++
rush/exo2/wst_from_tree.cc | 32 +++---
tests/sharp.cc | 147 +++++++++------------------
12 files changed, 663 insertions(+), 276 deletions(-)
Index: trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 3872)
+++ trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 3873)
@@ -47,6 +47,7 @@
#include "color_labeling_mean.hh"
/* WST */
+#include <mln/morpho/reconstruction/by_erosion/union_find.hh>
#include <mln/morpho/watershed/all.hh>
#include <mln/morpho/elementary/dilation.hh>
@@ -181,7 +182,6 @@
I input = color_internal_gradient(input_);
io::pgm::save(input, "gradient.pgm");
-
/***************************/
/* Component tree creation */
/***************************/
@@ -206,29 +206,37 @@
// Component filtering
- // this should use a filter from morpho/tree/filter with the predicate on the height of the parent
- // so use function composition but ...
+ // this should use a filter from morpho/tree/filter with the
+ // predicate on the height of the parent so use function
+ // composition but ...
+ // fixme : wrong height value !
mymin(t, a, pw::value(h_img) > pw::cst(lambda_h));
}
/************************************************/
/* Retrieve Components (Maximising the criteria)*/
/************************************************/
- A component_img;
- {
p_array< mln_psite_(A) > obj_array;
- I output = level::stretch(int_u8(), a); //adapt to 0-255
- io::pgm::save(output, "components.pgm");
+ {
+ //I output = level::stretch(int_u8(), a); //adapt to 0-255
+ //io::pgm::save(output, "components.pgm");
obj_array = morpho::tree::get_components(t, a);
std::cout << obj_array.nsites() << std::endl;
- component_img = morpho::tree::propagate_components(a, t, obj_array, 1.1);
+ }
- // debug
- //I output = level::stretch(int_u8(), component_img); //adapt to 0-255
- //io::pgm::save(output, "components.pgm");
+ I reconstructed;
+ {
+ I marker = set_value_to_components(t, obj_array, (int_u8) 0, (int_u8) 255);
+ set_value_to_components(t, input, obj_array, (int_u8) 0);
+
+ io::pgm::save(marker, "marker.pgm");
+
+ // input is the mask.
+ reconstructed = morpho::reconstruction::by_erosion::union_find(marker, input, c4());
+ io::pgm::save(reconstructed, "reconstructed.pgm");
}
@@ -237,7 +245,7 @@
/************************************************/
typedef image2d<int_u16> WST;
int_u16 n_basins = 0;
- WST wst = morpho::watershed::flooding(component_img, c4(), n_basins);
+ WST wst = morpho::watershed::flooding(reconstructed, c4(), n_basins);
if (!output_ || output_ == 1)
{
Index: trunk/milena/sandbox/edwin/tests/sharp.cc
===================================================================
--- trunk/milena/sandbox/edwin/tests/sharp.cc (revision 3872)
+++ trunk/milena/sandbox/edwin/tests/sharp.cc (revision 3873)
@@ -17,11 +17,12 @@
#include <mln/morpho/tree/propagate.hh>
/* Attributes */
-#include <mln/morpho/attribute/sharpness.hh>
+#include <mln/morpho/attribute/mysharpness.hh>
/* io */
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
/* data & pw */
#include <mln/core/concept/function.hh>
@@ -36,6 +37,7 @@
/* label */
#include <mln/labeling/blobs.hh>
#include <mln/value/label_16.hh>
+#include <mln/labeling/colorize.hh>
/* trace */
#include <mln/trace/quiet.hh>
@@ -67,41 +69,6 @@
namespace mln
{
- // Distance, stored on pixels, of neighboring colors.
-
- value::int_u8 dist_mean(const value::rgb8& c1, const value::rgb8& c2)
- {
- unsigned d = 0;
- d += (math::diff_abs(c1.red(), c2.red()) + 2) / 3;
- d += (math::diff_abs(c1.green(), c2.green()) + 2) / 3;
- d += (math::diff_abs(c1.blue(), c2.blue()) + 2) / 3;
- if (d > 255)
- d = 255;
- return d;
- }
-
- template <typename N>
- image2d<value::int_u8>
- dist_on_pixels(const image2d<value::rgb8>& input, const N& nbh)
- {
- using value::int_u8;
- image2d<int_u8> output(input.domain());
-
- mln_piter(box2d) p(input.domain());
- mln_niter(N) n(nbh, p);
- for_all(p)
- {
- int_u8 d = 0u;
- for_all(n) if (input.domain().has(n))
- {
- int_u8 d_ = dist_mean(input(p), input(n));
- if (d_ > d)
- d = d_;
- }
- output(p) = 255 - d;
- }
- return output;
- }
template <typename P2V>
struct height_wrapper_ : Function_p2v< height_wrapper_<P2V> >
@@ -161,6 +128,27 @@
return card_wrapper_<P2V>(f);
}
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ mymin(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)) || !pred(tree.parent(n)))
+ {
+ f(n) = 0.0;
+ mark(n) = true;
+ }
+ }
+
}
@@ -231,48 +219,24 @@
if (mydebug)
dsp("Image sharp attribute", timer);
- // TODO: l'attribut devrait favoriser les composantes plus larges
- // dans son calcul. Ainsi au lieu de faire un sharpness, on aurait
- // un ratio sharpness / hauteur de composante (reprendre l'idee du
- // log utilise pour INIM).
- typedef morpho::attribute::sharpness<I> sharp_t;
typedef mln_ch_value_(I, double) A;
- typedef mln_ch_value_(I, sharp_t) B;
-
- B a_img;
- A a = morpho::tree::compute_attribute_image(sharp_t (), tree, &a_img);
- // Note: then we work on nodes (component representant so we don't
- // need to propagate the representant value to the component sites.
-
-
- /***********************************/
- /* Components Filtering */
- /***********************************/
-
- // So we compute card attribute and we filter big components
- // FIXME: some attributes are compositions of attributes, here
- // sharpness can give area so, it would be fine if we could give an
- // optional extra argument to compute_attribute where the
- // accumulators image will be stored.
-
- if (card)
+ A a;
{
- if (mydebug)
- dsp("Image card attribute", timer);
+ typedef morpho::attribute::volume<I> v_attr;
+ typedef mln_ch_value_(I, unsigned) H;
+ typedef mln_ch_value_(I, v_attr) V;
+ H h_img;
+ V v_img;
- a = duplicate((fun::p2v::ternary(card_wrapper(pw::value(a_img)) > pw::cst(card),
- pw::value(a),
- pw::cst(0.0))) | a.domain());
- }
+ a = morpho::attribute::mysharpness(tree, &h_img, &v_img);
+ // Component filtering
if (height)
- {
- if (mydebug)
- dsp("Image height attribute", timer);
- a = duplicate((fun::p2v::ternary(height_wrapper(pw::value(a_img)) > pw::cst(height),
- pw::value(a),
- pw::cst(0.0))) | a.domain());
+ mymin(tree, a, pw::value(h_img) > pw::cst(height));
+
+ if (card)
+ morpho::tree::filter::filter(tree, a, card_wrapper(pw::value(v_img)) > pw::cst(card), 0.0);
}
/************************************************/
@@ -302,14 +266,6 @@
obj_array = morpho::tree::get_components(tree, a);
}
-
- /* Print them */
-// if (mydebug) {
-// mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
-// for_all(c)
-// std::cout << c;
-// }
-
/***********************************/
/* Use components in output image */
/***********************************/
@@ -328,27 +284,28 @@
// labeling
typedef mln_ch_value_(I, bool) M;
-
M mask = morpho::tree::set_value_to_components(tree, obj_array, true, false);
- //typedef mln_ch_value_(I, value::label<16>) L;
- //value::label<16> nlabel;
- //L label = labeling::blobs(mask, c4(), nlabel);
- //io::pgm::save(label, "label.pgm");
-
+ {
+ typedef mln_ch_value_(I, value::label<16>) L;
+ typedef mln_ch_value_(I, value::rgb<8>) O;
+ value::label<16> nlabel;
+ L label = labeling::blobs(mask, c4(), nlabel);
+ O output = labeling::colorize(value::rgb8(), label, nlabel);
+ io::ppm::save(output, "label.pgm");
+ }
if (mydebug) {
dsp("Finish", timer);
}
-
-
-// /* Now store output image */
- I out;
- initialize(out, input);
- data::fill(out, 0);
- data::paste(input | pw::value(mask), out);
- io::pgm::save(out, "output.pgm");
-
+ /* Now store output image */
+// {
+// I out;
+// initialize(out, input);
+// data::fill(out, 255);
+// data::paste(input | pw::value(mask), out);
+// io::pgm::save(out, "output.pgm");
+// }
}
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/propagate.hh (revision 3872)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/propagate.hh (revision 3873)
@@ -33,6 +33,7 @@
/// Functions to propagate a node value in the tree.
# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_representative.hh>
# include <mln/morpho/tree/propagate_node.hh>
namespace mln {
@@ -40,21 +41,6 @@
namespace tree {
- /// Propagate the representative point's value to
- /// non-representative node points.
- template <typename T, typename A>
- void
- propagate_representative(const T& t, Image<A>& a_)
- {
- A a = exact(a_);
- mln_up_site_piter(T) p(t);
- for_all(p)
- if (! t.is_a_node(p))
- {
- mln_assertion(t.is_a_node(t.parent(p)));
- a(p) = a(t.parent(p));
- }
- }
/**
** For each component in the list \p component_list, it
@@ -105,16 +91,55 @@
initialize(out, tree.f());
mln::data::fill(out, null);
- mln_piter(p_array< mln_psite(T) >) p(component_list);
- for_all(p)
{
+ mln_piter(p_array< mln_psite(T) >) n(component_list);
+ for_all(n)
+ out(n) = value;
+ }
+
+ {
+ mln_dn_site_piter(T) p(tree);
+ for_all(p)
+ if (out(tree.parent(p)) == value)
out(p) = value;
- morpho::tree::propagate_node_to_descendants(p, tree, out);
}
- morpho::tree::propagate_representative(tree, out);
return out;
}
+ template <typename T, typename F>
+ inline
+ void
+ set_value_to_components(const T& tree,
+ Image<F>& f_,
+ const p_array< mln_psite(T) >& component_list,
+ const mln_value(F)& value)
+ {
+ F& f = exact(f_);
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ {
+ mln_piter(p_array< mln_psite(T) >) n(component_list);
+ for_all(n)
+ {
+ mark(n) = true;
+ f(n) = value;
+ }
+ }
+
+ {
+ mln_dn_site_piter(T) p(tree);
+ for_all(p)
+ if (mark(tree.parent(p)))
+ {
+ mark(p) = true;
+ f(p) = value;
+ }
+ }
+ }
+
} // end of namespace mln::morpho::tree
} // end of namespace mln::morpho
} // end of namespace mln
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_representative.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_representative.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_representative.hh (revision 3873)
@@ -0,0 +1,76 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_
+
+/// \file mln/morpho/tree/propagate_representative.hh
+///
+/// Component tree routines.
+
+namespace mln{
+ namespace morpho {
+ namespace tree {
+
+ /**
+ ** Propagate the representative node's value to
+ ** non-representative points of the component.
+ **
+ ** @param t Component tree.
+ ** @param f_ Value image.
+ */
+ template <typename T, typename F>
+ void
+ propagate_representative(const T& t, Image<F>& f_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F>
+ inline
+ void
+ propagate_representative(const T& t, Image<F>& f_)
+ {
+ F a = exact(f_);
+ mln_up_site_piter(T) p(t);
+ for_all(p)
+ if (! t.is_a_node(p))
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p));
+ }
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ }
+ }
+}
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter.hh (revision 3872)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter.hh (revision 3873)
@@ -56,59 +56,7 @@
filter(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_, const mln_value(F)& v);
- template <typename T, typename F, typename P2B>
- inline
- void
- min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
-
-
- template <typename T, typename F, typename P2B>
- inline
- void
- max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
-
- template <typename T, typename F, typename P2B>
- inline
- void
- direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
-
- template <typename T, typename F, typename P2B>
- inline
- void
- subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
-
-
# ifndef MLN_INCLUDE_ONLY
- namespace internal
- {
-
- template <typename P2B>
- struct not_pred_ : Function_p2b< not_pred_<P2B> >
- {
- not_pred_(const Function_p2b<P2B>& f) :
- f_ (exact(f))
- {
- }
-
- template <typename P>
- bool operator() (const P& p) const
- {
- return !(f_(p));
- }
-
- private:
- const P2B& f_;
- };
-
- template <typename P2B>
- inline
- not_pred_<P2B>
- not_pred(const Function_p2b<P2B>& f)
- {
- return not_pred_<P2B>(f);
- }
-
- }
template <typename T, typename F, typename P2B>
inline
@@ -118,31 +66,8 @@
F& f = exact(f_);
const P2B& pred = exact(pred_);
- //FIXME precondition
- mln_ch_value(F, bool) mark;
- initialize(mark, f);
- mln::data::fill(mark, false);
-
- mln_dn_node_piter(T) n(tree);
- for_all(n)
- if (mark(tree.parent(n)) || !pred(n))
- {
- f(n) = v;
- mark(n) = true;
- }
- //FIXME postcondition
- }
-
-
- template <typename T, typename F, typename P2B>
- inline
- void
- min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
- {
- F& f = exact(f_);
- const P2B& pred = exact(pred_);
+ trace::entering("mln::morpho::tree::filter::filter");
- //FIXME precondition
mln_ch_value(F, bool) mark;
initialize(mark, f);
mln::data::fill(mark, false);
@@ -151,78 +76,11 @@
for_all(n)
if (mark(tree.parent(n)) || !pred(n))
{
- f(n) = f(tree.parent(n));
+ f(n) = v;
mark(n) = true;
}
- //FIXME postcondition
- }
-
- template <typename T, typename F, typename P2B>
- inline
- void
- max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
- {
- F& f = exact(f_);
- const P2B& pred = exact(pred_);
- //FIXME precondition
- mln_ch_value(F, bool) mark;
- initialize(mark, f);
- mln::data::fill(mark, true);
-
- {
- mln_up_node_piter(T) n(tree);
- for_all(n)
- if (!mark(n))
- mark(tree.parent(n)) = false;
- else if (pred(n))
- {
- mark(tree.parent(n)) = false;
- mark(n) = false;
- }
- }
-
- {
- mln_dn_node_piter(T) n(tree);
- for_all(n)
- if (mark(n))
- f(n) = f(tree.parent(n));
- }
- }
-
- template <typename T, typename F, typename P2B>
- inline
- void
- direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
- {
- F& f = exact(f_);
- const P2B& pred = exact(pred_);
-
- //FIXME precondition
- mln_dn_node_piter(T) n(tree);
- for_all(n)
- if (!pred(n))
- f(n) = f(tree.parent(n));
- //FIXME postcondition
- }
-
- template <typename T, typename F, typename P2B>
- inline
- void
- subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
- {
- F& f = exact(f_);
- const P2B& pred = exact(pred_);
-
- //FIXME precondition
-
- morpho::tree::propagate_if(tree, f, morpho::tree::desc_propagation (), internal::not_pred(pred));
-
- mln_up_node_piter(T) n(tree);
- for_all(n)
- if (!pred(n))
- f(n) = f(tree.parent(n));
- //FIXME postcondition
+ trace::exiting("mln::morpho::tree::filter::filter");
}
# endif /* !MLN_INCLUDE_ONLY */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter/min.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter/min.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter/min.hh (revision 3873)
@@ -0,0 +1,100 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_MIN_HH_
+# define MLN_MORPHO_TREE_FILTER_MIN_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+
+/**
+** @file mln/morpho/tree/filter/min.hh
+**
+** @brief Filtering with min strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+
+ /**
+ ** Min pruning strategy. A node is removed iif its parent is
+ ** removed or if it does not verify the predicate \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::min");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)) || !pred(n))
+ {
+ f(n) = f(tree.parent(n));
+ mark(n) = true;
+ }
+
+ trace::exiting("mln::morpho::tree::filter::min");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MIN_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter/max.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter/max.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter/max.hh (revision 3873)
@@ -0,0 +1,110 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_MAX_HH_
+# define MLN_MORPHO_TREE_FILTER_MAX_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/max.hh
+**
+** @brief Filtering with max strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Max pruning strategy. A node is removed iif all of its
+ ** children are removed or if it does not verify the predicate
+ ** \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::max");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, true);
+
+ {
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!mark(n))
+ mark(tree.parent(n)) = false;
+ else if (pred(n))
+ {
+ mark(tree.parent(n)) = false;
+ mark(n) = false;
+ }
+ }
+
+ {
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(n))
+ f(n) = f(tree.parent(n));
+ }
+
+ trace::exiting("mln::morpho::tree::filter::max");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MAX_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter/all.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter/all.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter/all.hh (revision 3873)
@@ -0,0 +1,66 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_ALL_HH_
+# define MLN_MORPHO_TREE_FILTER_ALL_HH_
+
+/**
+** @file mln/morpho/tree/filter.hh
+**
+** Methods to handle component tree filtering strategies with
+** non-increasing attribute. Nevertheless, it works on increasing
+** predicate as well. In this case, all strategies have the same
+** result but min filter or direct filter should be used in term
+** of performance. If a predicate test is too slow, then consider
+** the min filter that minimizes calls to predicate function.
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ /// Namespace for attribute filtering.
+ namespace filter {
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+
+// Pruning strategies.
+# include <mln/morpho/tree/filter/min.hh>
+# include <mln/morpho/tree/filter/max.hh>
+
+// Non-pruning stategies.
+# include <mln/morpho/tree/filter/direct.hh>
+# include <mln/morpho/tree/filter/subtractive.hh>
+
+
+
+#endif /* !MLN_MORPHO_TREE_FILTER_ALL_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter/direct.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter/direct.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter/direct.hh (revision 3873)
@@ -0,0 +1,91 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_DIRECT_HH_
+# define MLN_MORPHO_TREE_FILTER_DIRECT_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/direct.hh
+**
+** @brief Filtering with direct strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Direct non-pruning strategy. A node is removed if it does
+ ** not verify the predicate. The sub-components remain intact.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::direct");
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::direct");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_DIRECT_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/filter/subtractive.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/filter/subtractive.hh (revision 0)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/filter/subtractive.hh (revision 3873)
@@ -0,0 +1,97 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_
+# define MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/fun/ops.hh>
+
+# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_if.hh>
+
+/**
+** @file mln/morpho/tree/filter/subtractive.hh
+**
+** @brief Filtering with subtractive strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Subtractive pruning strategy. The node is removed if it
+ ** does not verify the predicate. The sub-components values
+ ** are set to the value of the removed component.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::subtractive");
+
+ morpho::tree::propagate_if(tree, f, morpho::tree::desc_propagation (), !pred);
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::subtractive");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_ */
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_node.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_node.hh (revision 3872)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_node.hh (revision 3873)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// Copyright (C) 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
@@ -78,7 +78,7 @@
/**
- ** Propagate a value \v from a node \n to its ancestors.
+ ** Propagate a value \p v from a node \p n to its ancestors.
**
** @param n Node to propagate.
** @param t Component tree used for propagation.
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_if.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_if.hh (revision 3872)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_if.hh (revision 3873)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// Copyright (C) 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
@@ -32,8 +32,7 @@
/**
** @file mln/morpho/tree/propagate_if.hh
**
-** @brief Methods to handle propagation startegies
-** in component trees.
+** @brief Routines to handle propagation with predicate.
**
*/