URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-25 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Separate propagation method and some tries about attributes.
* edwin/filtres/connectes/Makefile
* edwin/filtres/connectes/connected_filter.hh: Fix some bugs.
* edwin/tree/Makefile: New.
* edwin/tree/propagate.hh: Propagation methods.
* edwin/tree/tree.cc: New.
* edwin/tree: New.
---
filtres/connectes/Makefile | 4
filtres/connectes/connected_filter.hh | 67 +--------------
tree/Makefile | 33 +++++++
tree/propagate.hh | 77 ++++++++++++++++++
tree/tree.cc | 144 ++++++++++++++++++++++++++++++++++
5 files changed, 259 insertions(+), 66 deletions(-)
Index: trunk/milena/sandbox/edwin/tree/propagate.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 0)
+++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3426)
@@ -0,0 +1,77 @@
+// Copyright (C) 2008 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_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_HH_
+
+/// \file mln/morpho/tree/propagate.hh
+///
+/// Functions to propagate a node value in the tree.
+
+#include <mln/morpho/tree/data.hh>
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+
+ /// The representative point propagates its value to
+ /// its non-representative children nodes.
+ template <typename T, typename A>
+ void
+ back_propagate_level(const T& t, A& a)
+ {
+ mln_fwd_piter(T) p(t.domain());
+ for_all(p)
+ if (! t.is_a_node(p))
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p));
+ }
+ }
+
+ /// The representative point having the right
+ /// value propagates to the nodes of its sub-branch.
+ template <typename T, typename A>
+ void
+ back_propagate_subbranch(const T& t, A& a, mln_value(A) v)
+ {
+ mln_fwd_piter(T) p(t.domain());
+ for_all(p)
+ if (t.is_a_node(p) && a(t.parent(p)) == v)
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p));
+ }
+ }
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_HH_ */
+
+
Index: trunk/milena/sandbox/edwin/tree/tree.cc
===================================================================
--- trunk/milena/sandbox/edwin/tree/tree.cc (revision 0)
+++ trunk/milena/sandbox/edwin/tree/tree.cc (revision 3426)
@@ -0,0 +1,144 @@
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/routine/duplicate.hh>
+#include <mln/pw/all.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label_8.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <mln/level/sort_psites.hh>
+#include <mln/morpho/elementary/gradient.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/morpho/attribute/card.hh>
+
+#include <mln/debug/println.hh>
+
+
+namespace mln
+{
+
+ template <typename T, typename A>
+ void
+ back_propagate(const T& t, A& a)
+ // a value propagates from the representative point to every point
+ // of the component at the same level (NOT to the branch points!)
+ {
+ mln_fwd_piter(T) p(t.domain());
+ for_all(p)
+ if (! t.is_a_node(p))
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p)); // ...here!
+ }
+ }
+
+
+ template <typename T, typename A>
+ void
+ back_propagate_II(const T& t, A& a)
+ // a value propagates from a representative point to every point
+ // of the component and the children components (branch).
+ {
+ mln_bkd_piter(T) p(t.domain());
+ for_all(p)
+ if (t.is_a_node(p) && a(t.parent(p)) == true)
+ a(p) = a(t.parent(p));
+ }
+
+
+ template <typename T, typename A>
+ inline
+ void
+ sample(const T& t, const A& a, int echo)
+ {
+ A aa;
+ initialize(aa, a);
+ data::fill(aa, false); // 'aa' is false /a priori/.
+
+ typedef typename T::nodes_t N;
+ mln_fwd_piter(N) n(t.nodes());
+ for_all(n)
+ // We only keep "highest" nodes at 'true' => largest
component.
+ aa(n) = (a(n) == true && a(t.parent(n)) == false);
+
+ if (echo) io::pbm::save(aa, "before.pbm");
+ if (echo > 1) debug::println("aa (before)", aa);
+
+ back_propagate_II(t, aa);
+ back_propagate(t, aa);
+
+ if (echo > 1) debug::println("aa (after)", aa);
+ io::pbm::save(aa, "out.pbm");
+
+ }
+
+} // mln
+
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm echo
lambda" << std::endl;
+ std::cerr << " echo: 0 (none) or 1 (verbose)" << std::endl;
+ abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ mln_VAR(nbh, c4());
+
+ if (argc != 4)
+ usage(argv);
+
+ int echo = std::atoi(argv[2]);
+ if (echo != 0 && echo != 1)
+ {
+ std::cerr << "bad 'echo' value!" << std::endl;
+ usage(argv);
+ }
+
+ typedef image2d<int_u8> I;
+
+ I input;
+ io::pgm::load(input, argv[1]);
+ if (echo > 1) debug::println("input", input);
+
+ I f = input;
+ // I f = morpho::elementary::gradient(input, nbh);
+ if (echo > 1) debug::println("f", f);
+
+
+ typedef p_array<point2d> S;
+ S s = level::sort_psites_decreasing(f);
+
+ typedef morpho::tree::data<I,S> tree_t;
+ tree_t t(f, s, nbh);
+
+ morpho::attribute::card<I> a_;
+ mln_VAR(a, morpho::tree::compute_attribute_image(a_, t));
+
+ if (echo > 1)
+ {
+ debug::println("parent imagee", t.parent_image());
+ debug::println("a", a);
+ debug::println("a | nodes", a | t.nodes());
+ }
+
+ image2d<bool> b = duplicate((pw::value(a) < pw::cst(atoi(argv[3]))) |
a.domain());
+ if (echo > 1) debug::println("b", b | t.nodes());
+
+ sample(t, b, echo);
+}
Index: trunk/milena/sandbox/edwin/tree/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/tree/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/tree/Makefile (revision 3426)
@@ -0,0 +1,33 @@
+TARGET=a.out
+SRC=edwin.cc
+OBJS=${SRC:.cc=.o}
+
+OLENADIR=../../..
+MILENADIR=$(OLENADIR)/milena
+
+CXXFLAGS=-I$(MILENADIR) -I./
+
+CXXFLAGS += "-DNDEBUG -O1"
+
+
+CXX=g++
+LD=g++
+LDFLAGS=
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(SRC)
+ $(LD) $(LDFLAGS) -o $@ $(OBJS)
+
+
+$(REF): $(OBJS_REF) $(SRC_REF)
+ $(LD) $(LDFLAGS) -o $@ $(OBJS_REF)
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
+
+%.o: %.hh
+ $(CXX) $(CXXFLAGS) -c $<
+
+clean:
+ rm -f *.o $(REF) $(TARGET)
\ No newline at end of file
Index: trunk/milena/sandbox/edwin/filtres/connectes/connected_filter.hh
===================================================================
--- trunk/milena/sandbox/edwin/filtres/connectes/connected_filter.hh (revision 3425)
+++ trunk/milena/sandbox/edwin/filtres/connectes/connected_filter.hh (revision 3426)
@@ -74,6 +74,8 @@
void take_as_init_fastest (trait::accumulator::when_pix::use_none, A& accu,
const I& input, const unsigned p)
{
+ (void)input;
+ (void)p;
accu.take_as_init ();
}
@@ -81,6 +83,7 @@
void take_as_init (trait::accumulator::when_pix::use_p, A& accu,
const I& input, const P& p)
{
+ (void)input;
accu.take_as_init (p);
}
@@ -88,6 +91,7 @@
void take_as_init (trait::accumulator::when_pix::use_none, A& accu,
const I& input, const P& p)
{
+ (void)input;
accu.take_as_init (p);
}
@@ -279,11 +283,11 @@
const typename A::result& lambda)
{
trace::entering("canvas::morpho::impl::connected_filter_fastest");
-
// FIXME: Tests?
const I& input = exact(input_);
const N& nbh = exact(nbh_);
+ (void)a_;
mln_concrete(I) output;
initialize(output, input);
@@ -372,71 +376,10 @@
} // end of namespace mln::canvas::morpho::impl
-
-
// Dispatch.
-
namespace internal
{
- // Leveling
- template <typename I, typename N, typename A>
- mln_concrete(I)
- leveling_filter_dispatch(metal::false_,
- const Image<I>& input,
- const Neighborhood<N>& nbh,
- const Accumulator<A>& a,
- const typename A::result& lambda,
- bool increasing)
- {
- p_array < mln_psite(I) > s =
- increasing ?
- level::sort_psites_increasing(input) :
- level::sort_psites_decreasing(input);
- return impl::generic::connected_filter(input, nbh, s, a, lambda);
- }
-
- template <typename I, typename N, typename A>
- mln_concrete(I)
- leveling_filter_dispatch(metal::true_,
- const Image<I>& input,
- const Neighborhood<N>& nbh,
- const Accumulator<A>& a,
- const typename A::result& lambda,
- bool increasing)
- {
- util::array<unsigned> s =
- increasing ?
- level::sort_offsets_increasing(input) :
- level::sort_offsets_decreasing(input);
- return impl::connected_filter_fastest(input, nbh, s, a, lambda);
- }
-
- template <typename I, typename N, typename A>
- inline
- mln_concrete(I)
- leveling_filter_dispatch(const Image<I>& input,
- const Neighborhood<N>& nbh,
- const Accumulator<A>& a,
- const typename A::result& lambda,
- bool increasing)
- {
- mlc_or(mlc_equal(mln_trait_accumulator_when_pix(A),
- trait::accumulator::when_pix::use_pix),
- mlc_equal(mln_trait_accumulator_when_pix(A),
- trait::accumulator::when_pix::use_v))::check();
-
- enum
- {
- test = mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value
- && mlc_equal(mln_trait_accumulator_when_pix(A),
- trait::accumulator::when_pix::use_v)::value
- && mln_is_simple_neighborhood(N)::value
- };
- return leveling_filter_dispatch(metal::bool_<test>(),
- input, nbh, a, lambda, increasing);
- }
// Alegebraic
template <typename I, typename N, typename A>
Index: trunk/milena/sandbox/edwin/filtres/connectes/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/filtres/connectes/Makefile (revision 3425)
+++ trunk/milena/sandbox/edwin/filtres/connectes/Makefile (revision 3426)
@@ -1,9 +1,6 @@
TARGET=filter
-REF=leveling
SRC=filter.cc
-SRC_REF=leveling.cc
OBJS=${SRC:.cc=.o}
-OBJS_REF=${SRC_REF:.cc=.o}
OLENADIR=../../../../..
MILENADIR=$(OLENADIR)/milena
@@ -29,4 +26,4 @@
$(CXX) $(CXXFLAGS) -c $<
clean:
- rm -f *.o $(REF) $(TARGET)
\ No newline at end of file
+ rm -f *.o *.pgm $(TARGET)
\ No newline at end of file