3202: Cleanup organization related to ISMM code.

https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Cleanup organization related to ISMM code. * theo/esiee/laurent: New directory. * theo/laurent/wst_edge.cc, * theo/laurent/wst2d.cc, * theo/laurent/classif.cc, * theo/laurent/wst3d.cc: Move into... * theo/esiee/laurent/presentation: ...this new directory. * theo/laurent: Remove. * laurent/ismm2009.v0.cc, * laurent/ismm2009.v1.cc, * laurent/ismm2009.v2.cc: Move into... * laurent/memo: ...this new directory. * laurent/ismm2009.cc (n_basins): Move log. (FIXME): New. * laurent/playing_with_attributes.cc (test_attribute_growing_property): New. (change_tree_attributes): Rename as.. (attribute_extinction): ...this. (rec, NEW___extinct_attributes): New. * theo/esiee/laurent/ismm09: New directory. * theo/esiee/laurent/ismm09/main.cc: New. laurent/ismm2009.cc | 11 ++ laurent/playing_with_attributes.cc | 116 ++++++++++++++++++++++---- theo/esiee/laurent/ismm09/main.cc | 161 +++++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+), 19 deletions(-) Index: theo/esiee/laurent/ismm09/main.cc --- theo/esiee/laurent/ismm09/main.cc (revision 0) +++ theo/esiee/laurent/ismm09/main.cc (revision 0) @@ -0,0 +1,161 @@ + +#include <mln/core/var.hh> + +#include <mln/core/image/image2d.hh> +#include <mln/make/double_neighb2d.hh> + +#include <mln/core/image/image_if.hh> +#include <mln/core/routine/extend.hh> + +#include <mln/value/label_16.hh> +#include <mln/value/int_u8.hh> +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> +#include <mln/debug/println.hh> + +#include <mln/data/fill.hh> +#include <mln/data/paste.hh> + +#include <mln/morpho/gradient.hh> + + +namespace mln +{ + + + + template <typename I, typename J> + void data__paste_values(const Image<I>& input_, Image<J>& output_) + { + const I& input = exact(input_); + J& output = exact(output_); + + mln_fwd_piter(I) pi(input.domain()); + mln_fwd_piter(J) po(output.domain()); + for_all_2(pi, po) + output(po) = input(pi); + } + + + + namespace cplx2d + { + + // Neighborhoods. + + typedef neighb< win::multiple<window2d, bool(*)(const point2d&)> > dbl_neighb2d; + + inline + bool is_row_odd(const point2d& p) + { + return p.row() % 2; + } + + // Edge to (the couple of) pixels. + const dbl_neighb2d& e2p() + { + static bool e2p_h[] = { 0, 1, 0, + 0, 0, 0, + 0, 1, 0 }; + static bool e2p_v[] = { 0, 0, 0, + 1, 0, 1, + 0, 0, 0 }; + static dbl_neighb2d nbh = make::double_neighb2d(is_row_odd, e2p_h, e2p_v); + return nbh; + } + + + // Edge to neighboring edges. + const dbl_neighb2d& e2e() + { + static bool e2e_h[] = { 0, 0, 1, 0, 0, + 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, + 0, 0, 1, 0, 0 }; + static bool e2e_v[] = { 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, + 1, 0, 0, 0, 1, + 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0 }; + static dbl_neighb2d nbh = make::double_neighb2d(is_row_odd, e2e_h, e2e_v); + return nbh; + } + + + // Predicates. + + typedef fun::C<bool (*)(const mln::point2d&)> predicate_t; + + inline + bool is_pixel(const point2d& p) + { + // Original pixels. + return p.row() % 2 == 0 && p.col() % 2 == 0; + } + + inline + bool is_edge(const point2d& p) + { + // Edges between pixels. + return p.row() % 2 + p.col() % 2 == 1; + } + + inline + bool is_point(const point2d& p) + { + // Points in-between pixels. + return p.row() % 2 && p.col() % 2; + } + + + image_if< image2d<value::int_u8>, predicate_t > + f_to_g(const image2d<value::int_u8>& f) + { + + image2d<value::int_u8> f_(2 * f.nrows() - 1, 2 * f.ncols() - 1); + data::fill(f_, 0); // Useless but for display! + + data__paste_values(f, (f_ | is_pixel).rw()); + debug::println(f_ | is_pixel); + + mln_VAR(g, f_ | is_edge); + data::paste(morpho::gradient(extend(g, f_), + e2p().win()), + g); + debug::println(g); + + return g; + } + + + } // end of namespace mln::face2 + +} // end of namespace mln + + +void usage(char* argv[]) +{ + std::cerr << "usage: " << argv[0] << " input.pgm echo output.pgm" << std::endl; + std::cerr << "Laurent ISMM 2009 scheme with saliency map as output." << std::endl; + std::cerr << " echo = 0 or 1." << std::endl; + abort(); +} + + + + +int main(int argc, char* argv[]) +{ + using namespace mln; + using value::int_u8; + using value::label_16; + + if (argc != 4) + usage(argv); + + image2d<int_u8> f; + io::pgm::load(f, argv[1]); + + mln_VAR(g, cplx2d::f_to_g(f) ); +} Index: laurent/ismm2009.cc --- laurent/ismm2009.cc (revision 3201) +++ laurent/ismm2009.cc (working copy) @@ -18,7 +18,9 @@ #include <mln/level/stretch.hh> #include <mln/labeling/compute.hh> + #include <mln/accu/count.hh> +#include <mln/accu/height.hh> #include <mln/util/timer.hh> #include <mln/util/fibonacci_heap.hh> @@ -479,14 +481,14 @@ compute_wst_g_from_f(f, g, e2p(), e2e(), n_basins, echo) ); - std::cout << "n basins = " << n_basins << std::endl; - if (echo) { debug::println("g:", g); debug::println("wst(g):", wst_g); } + std::cout << "n basins = " << n_basins << std::endl; + // Just to see things. @@ -542,6 +544,11 @@ // Compute an attribute per region. // -------------------------------- + { + // Height. + // FIXME: HERE... + } + typedef unsigned A; util::array<A> a = labeling::compute(accu::meta::count(), g, Index: laurent/playing_with_attributes.cc --- laurent/playing_with_attributes.cc (revision 3201) +++ laurent/playing_with_attributes.cc (working copy) @@ -49,6 +49,29 @@ }; + // FIXME: HERE + + + template <typename T, typename I> + bool + test_attribute_growing_property(const T& t, // Tree. + const I& a) // Attribute image. + { + typedef mln_site(I) P; + typedef mln_value(I) A; // Type of attributes. + + // Test that attributes increase with parenthood. + mln_fwd_piter(T) p(t.domain()); + for_all(p) + if (t.is_a_non_root_node(p)) + { + mln_invariant(t.is_a_node(t.parent(p))); + if (a(t.parent(p)) < a(p)) + return false; + } + return true; + } + template <typename T, typename I> void depict_tree_attributes(const T& t, // Tree. @@ -81,29 +104,25 @@ } + + // Attribute extinction (reference code). + // -------------------------------------- + + template <typename T, typename I> mln_concrete(I) - change_tree_attributes(const T& t, // Tree. + attribute_extinction(const T& t, // Tree. const I& a, // Attribute image. bool echo = false) { typedef mln_site(I) P; typedef mln_value(I) A; // Type of attributes. - // Test that attributes increase with parenthood. - mln_fwd_piter(T) p(t.domain()); - for_all(p) - if (t.is_a_non_root_node(p)) - { - mln_assertion(t.is_a_node(t.parent(p))); - mln_invariant(a(t.parent(p)) >= a(p)); - } - + mln_assertion( test_attribute_growing_property(t, a) ); if (echo) depict_tree_attributes(t, a); - node_pred<T> node_only; node_only.t = &t; @@ -220,7 +239,63 @@ -} // mln + + + + // N E W C O D E = = Attribute extinction (reference code). + // -------------------------------------- + + template <typename T, typename I, typename M> + mln_value(I) rec(const T& t, // tree + I& a, // attribute image + M& mark, + const mln_psite(I)& p) + { + mln_invariant(mark(p) == false); + mark(p) = true; + if (t.parent(p) == p || mark(t.parent(p)) == true) // Stop. + return a(p); + return a(p) = rec(t, a, mark, t.parent(p)); + } + + + template <typename T, typename I> + void + NEW___extinct_attributes(const T& t, // Tree. + I& a, // Attribute image. + bool echo = false) + { + typedef mln_site(I) P; + typedef mln_value(I) A; // Type of attributes. + + if (echo) + depict_tree_attributes(t, a); + + + mln_ch_value(I, bool) mark; + initialize(mark, a); + data::fill(mark, false); + + node_pred<T> node_only; + node_only.t = &t; + + typedef p_array<P> S; + S s = level::sort_psites_increasing(a | node_only); + mln_invariant(geom::nsites(a | t.nodes()) == s.nsites()); + + mln_fwd_piter(S) p(s); + for_all(p) + { + if (mark(p) == true) + continue; + rec(t, a, mark, p); + } + + debug::println(mark | t.nodes()); + } + + +} // mln ------------------------------------------------------------ @@ -255,7 +330,14 @@ mln_ch_value(I,unsigned) a = morpho::tree::compute_attribute_image(a_, t); debug::println("a | nodes:", a | t.nodes()); - mln_ch_value(I,unsigned) aa = change_tree_attributes(t, a); + + // Reference version. +// mln_ch_value(I,unsigned) aa = attribute_extinction(t, a); + + // NEW version. + NEW___extinct_attributes(t, a); + mln_VAR(aa, a); + debug::println("aa | nodes:", aa | t.nodes()); // Back-propagation from nodes to components. @@ -269,8 +351,8 @@ } } - debug::println("a | w line:", a | (pw::value(w) == pw::cst(0))); - debug::println("aa | w line:", aa | (pw::value(w) == pw::cst(0))); +// debug::println("a | w line:", a | (pw::value(w) == pw::cst(0))); +// debug::println("aa | w line:", aa | (pw::value(w) == pw::cst(0))); // debug::println("a | w basins:", a | (pw::value(w) != pw::cst(0))); // debug::println("a | regmin:", a | (pw::value(regmin) != pw::cst(0))); @@ -301,13 +383,13 @@ I f_ = add_edges(raw_f); mln_VAR(f, f_ | is_pixel); - debug::println("f:", f); + // debug::println("f:", f); mln_VAR(g, f_ | is_edge); data::paste( morpho::gradient(extend(g, f_), e2p().win()), g ); - debug::println("g:", g); + // debug::println("g:", g); L n; do_it(g, e2e(), n);
participants (1)
-
Thierry Geraud