https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
New ESIEE stuff.
* theo/esiee/slides_2009_may: New.
* theo/esiee/slides_2009_may/dilation.hh: New.
* theo/esiee/slides_2009_may/main.cc: New.
* theo/esiee/laurent/ismm09/extinct_attributes.hh: New.
* theo/esiee/laurent/ismm09/main.ext.cc: New.
laurent/ismm09/extinct_attributes.hh | 136 +++++++++++++++++++++++++++++++++++
laurent/ismm09/main.ext.cc | 76 +++++++++++++++++++
slides_2009_may/dilation.hh | 70 ++++++++++++++++++
slides_2009_may/main.cc | 31 +++++++
4 files changed, 313 insertions(+)
Index: theo/esiee/slides_2009_may/dilation.hh
--- theo/esiee/slides_2009_may/dilation.hh (revision 0)
+++ theo/esiee/slides_2009_may/dilation.hh (revision 0)
@@ -0,0 +1,70 @@
+
+#include <mln/pw/image.hh>
+#include <mln/convert/to_fun.hh>
+#include <mln/accu/max.hh>
+
+
+namespace mln
+{
+
+ // To be added in mln/pw/image.hh
+
+ template <typename V, typename P, typename S>
+ pw::image< fun::C<V(*)(P)>, S >
+ operator | (V (*f)(P), const S& s)
+ {
+ return convert::to_fun(f) | s;
+ }
+
+
+// namespace accu
+// {
+// template <typename T> struct sup : max<T> {};
+// }
+
+
+ namespace accu
+ {
+ template <typename T>
+ struct sup : public accu::internal::base< T, sup<T> >
+ {
+ typedef T argument;
+ T t_;
+
+ void init() { t_ = mln_min(T); }
+ void take(const T& t) { if (t > t_) t_ = t; }
+ void take(const sup& o) { if (o.t_ > t_) t_ = o.t_; }
+ T to_result() const { return t_; }
+ bool is_valid() const { return true; }
+ };
+
+ } // mln::accu
+
+
+ namespace morpho
+ {
+
+ template <typename I, typename W>
+ mln_concrete(I) dilation(const I& ima, const W& win)
+ {
+ mln_concrete(I) out;
+ initialize(out, ima);
+
+ mln_piter(I) p(ima.domain());
+ mln_qiter(W) q(win, p);
+ accu::sup<mln_value(I)> sup;
+
+ for_all(p)
+ {
+ sup.init();
+ for_all(q) if (ima.has(q))
+ sup.take(ima(q));
+ out(p) = sup;
+ }
+
+ return out;
+ }
+
+ } // mln::morpho
+
+} // mln
Index: theo/esiee/slides_2009_may/main.cc
--- theo/esiee/slides_2009_may/main.cc (revision 0)
+++ theo/esiee/slides_2009_may/main.cc (revision 0)
@@ -0,0 +1,31 @@
+#include <mln/core/var.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+#include "dilation.hh"
+
+
+
+int slope(mln::point2d p)
+{
+ return p.row() + p.col();
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<int> ima(2,2);
+ debug::iota(ima);
+ debug::println(ima);
+
+ debug::println(morpho::dilation(ima,
+ win_c4p()) );
+
+ mln_VAR(ima2, slope | box2d(3,3));
+ debug::println(ima2);
+ debug::println(morpho::dilation(ima2, c4().win()) );
+}
Index: theo/esiee/laurent/ismm09/extinct_attributes.hh
--- theo/esiee/laurent/ismm09/extinct_attributes.hh (revision 0)
+++ theo/esiee/laurent/ismm09/extinct_attributes.hh (revision 0)
@@ -0,0 +1,136 @@
+
+namespace mln
+{
+
+ // Display.
+ // --------
+
+
+ template <typename T, typename I>
+ void display_tree_attributes(const T& t, // Tree.
+ const I& a) // Attribute image.
+ {
+ typedef mln_site(I) P;
+
+ mln_ch_value(I, bool) deja_vu;
+ initialize(deja_vu, a);
+ data::fill(deja_vu, false);
+
+ mln_up_node_piter(T) p(t);
+ for_all(p)
+ {
+ if (deja_vu(p))
+ continue;
+
+ P e = p;
+ do
+ {
+ std::cout << a(e) << ':' << e << " ->
";
+ deja_vu(e) = true;
+ e = t.parent(e);
+ }
+ while (! deja_vu(e));
+ std::cout << a(e) << ':' << e << std::endl;
+ }
+ std::cout << std::endl;
+ }
+
+
+ // Attribute Extinction.
+ // ---------------------
+
+ namespace internal
+ {
+
+ template <typename T>
+ struct node_pred : Function_p2b< node_pred<T> >
+ {
+ typedef bool result;
+
+ template <typename P>
+ bool operator()(const P& p) const
+ {
+ return t->is_a_node(p);
+ }
+
+ const T* t;
+ };
+
+
+ // Vachier's version.
+
+ template <typename T, typename I, typename M>
+ inline
+ mln_value(I)
+ extinct_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) = extinct_rec(t, a, mark, t.parent(p));
+ }
+
+
+ } // end of internal
+
+
+ // Vachier's version.
+
+ template <typename T, typename I>
+ void
+ extinct_attributes(const T& t, // Tree.
+ I& a, // Attribute image.
+ bool echo = false)
+ {
+ if (echo)
+ {
+ std::cout << "before:" << std::endl;
+ display_tree_attributes(t, a);
+ }
+
+ typedef mln_site(I) P;
+ typedef mln_value(I) A; // Type of attributes.
+
+ mln_ch_value(I, bool) mark;
+ initialize(mark, a);
+ data::fill(mark, false);
+
+ internal::node_pred<T> node_only;
+ node_only.t = &t;
+
+ typedef p_array<P> S;
+ S s = level::sort_psites_increasing(a | node_only);
+
+// {
+// mln_fwd_piter(S) p(s);
+// for_all(p)
+// std::cout << p << ' ' << a(p) << " - ";
+// std::cout << std::endl
+// << std::endl;
+// }
+
+ mln_invariant(geom::nsites(a | t.nodes()) == s.nsites());
+
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ {
+ if (mark(p) == true)
+ continue;
+ internal::extinct_rec(t, a, mark, p);
+ }
+
+ // debug::println(mark | t.nodes());
+
+ if (echo)
+ {
+ std::cout << "after:" << std::endl;
+ display_tree_attributes(t, a);
+ }
+ }
+
+
+} // mln
Index: theo/esiee/laurent/ismm09/main.ext.cc
--- theo/esiee/laurent/ismm09/main.ext.cc (revision 0)
+++ theo/esiee/laurent/ismm09/main.ext.cc (revision 0)
@@ -0,0 +1,76 @@
+
+#include <mln/core/var.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/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/morpho/attribute/height.hh>
+#include <mln/labeling/regional_minima.hh>
+
+#include "cplx2d.hh"
+#include "extinct_attributes.hh"
+
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.pgm"
<< std::endl;
+ std::cerr << "Laurent ISMM 2009 scheme." << std::endl;
+ abort();
+}
+
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::label_16;
+
+ if (argc != 2)
+ usage(argv);
+
+ // f: regular image.
+
+ image2d<int_u8> f;
+ io::pgm::load(f, argv[1]);
+
+
+ // g: weights on edges.
+
+ mln_VAR(g, cplx2d::f_to_g(f) );
+ debug::println("g:", g);
+
+
+ // a: array "label -> attribute".
+
+ typedef unsigned A; // <--- Type of attributes.
+
+ {
+ typedef p_array<point2d> s_t;
+ s_t s = level::sort_psites_decreasing(g); // min-tree
+
+ typedef morpho::tree::data<g_t,s_t> tree_t;
+ tree_t t(g, s, cplx2d::e2e());
+
+ morpho::attribute::height<g_t> a;
+ mln_VAR(h, morpho::tree::compute_attribute_image(a, t));
+ debug::println("h:", h);
+
+ unsigned l_max;
+
+ mln_VAR(h_r, labeling::regional_minima(h, cplx2d::e2e(), l_max));
+ debug::println("h_r:", h_r);
+
+ extinct_attributes(t, h, /* echo = */ true);
+ debug::println("he | nodes:", h | t.nodes());
+ }
+
+}