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.
**
*/