https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update Laurent's cleanup code.
* theo/esiee/laurent/ismm09/main.cc: Update.
* theo/esiee/jean/pfg3d.cc: Update.
* igr/images/s7.ppm: Remove image.
jean/pfg3d.cc | 2
laurent/ismm09/main.cc | 169 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 167 insertions(+), 4 deletions(-)
Index: theo/esiee/laurent/ismm09/main.cc
--- theo/esiee/laurent/ismm09/main.cc (revision 3230)
+++ theo/esiee/laurent/ismm09/main.cc (working copy)
@@ -2,6 +2,7 @@
#include <mln/core/var.hh>
#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
#include <mln/make/double_neighb2d.hh>
#include <mln/core/image/image_if.hh>
@@ -15,8 +16,17 @@
#include <mln/data/fill.hh>
#include <mln/data/paste.hh>
+#include <mln/labeling/compute.hh>
+#include <mln/level/sort_psites.hh>
#include <mln/morpho/gradient.hh>
+#include <mln/morpho/meyer_wst.hh>
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+
+#include <mln/accu/count.hh>
+#include <mln/accu/height.hh>
+
namespace mln
@@ -109,6 +119,7 @@
}
+
image_if< image2d<value::int_u8>, predicate_t >
f_to_g(const image2d<value::int_u8>& f)
{
@@ -117,23 +128,138 @@
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
+ template <typename W>
+ image2d<mln_value(W)>
+ extend_w_edges_to_all_faces(W& w)
+ {
+ mln_VAR(w_ext, w.unmorph_());
+
+ // edges (1D-faces) -> pixels (2D-faces)
+ data::paste(morpho::dilation(extend(w_ext | is_pixel,
+ pw::value(w_ext)),
+ c4().win()),
+ w_ext);
+
+ // edges (1D-faces) -> points (0D-faces)
+ data::paste(morpho::erosion(extend(w_ext | is_point,
+ pw::value(w_ext)),
+ c4().win()),
+ w_ext);
+
+ return w_ext;
+ }
+
+
+ } // end of namespace mln::cplx2d
+
+
+ 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;
+ };
+
+ 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));
+ }
+
+ } // internal
+
+
+ template <typename T, typename A>
+ void
+ extinct_attributes(const T& t, // Tree.
+ A& a) // Attribute image.
+ {
+ mln_ch_value(A, bool) mark;
+ initialize(mark, a);
+ data::fill(mark, false);
+
+ internal::node_pred<T> node_only;
+ node_only.t = &t;
+
+ typedef p_array<mln_site(A)> S;
+ S s = level::sort_psites_increasing(a | node_only);
+
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ {
+ if (mark(p) == true)
+ continue;
+ internal::rec(t, a, mark, p);
+ }
+ }
+
+
+ template <typename F, typename N, typename A, typename W>
+ void // util::array<unsigned>
+ compute_attribute_extincted(const F& f, const N& nbh, const A& a,
+ const W& w)
+ {
+ typedef value::label_16 L;
+ L n_basins;
+ mln_ch_value(F,L) regmins = labeling::regional_minima(f, nbh, n_basins);
+
+ typedef p_array<mln_psite(F)> S;
+ S s = level::sort_psites_decreasing(f);
+
+ typedef morpho::tree::data<F,S> tree_t;
+ tree_t t(f, s, nbh);
+ mln_VAR(a_ima, morpho::tree::compute_attribute_image(a, t));
+
+ std::cout << "BEFORE:" << std::endl;
+ debug::println("a_ima:", a_ima);
+ debug::println("a_ima | w_line:", a_ima | (pw::value(w) == 0));
+ debug::println("a_ima | basins:", a_ima | (pw::value(w) != 0));
+ // debug::println("a_ima | regmins:", a_ima | (pw::value(regmins) != 0));
+
+
+ extinct_attributes(t, a_ima);
+
+ std::cout << "AFTER:" << std::endl;
+ debug::println("a_ima:", a_ima);
+ debug::println("a_ima | w_line:", a_ima | (pw::value(w) == 0));
+ debug::println("a_ima | basins:", a_ima | (pw::value(w) != 0));
+ debug::println("a_ima | regmins:", a_ima | (pw::value(regmins) != 0));
+ }
+
+
+
} // end of namespace mln
+
void usage(char* argv[])
{
std::cerr << "usage: " << argv[0] << " input.pgm echo
output.pgm" << std::endl;
@@ -154,8 +280,45 @@
if (argc != 4)
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);
+
+
+ // w: watershed labeling on edges.
+
+ typedef label_16 L;
+ L n_basins;
+ mln_VAR( w, morpho::meyer_wst(g, cplx2d::e2e(), n_basins) );
+
+ {
+ L n_regmins;
+ mln_VAR(regmins, labeling::regional_minima(g, cplx2d::e2e(), n_regmins));
+ mln_invariant(n_regmins == n_basins);
+ debug::println("regmins(g):", regmins);
+
+ debug::println("w:", w);
+ std::cout << "n basins = " << n_basins << std::endl
+ << std::endl;
+
+// mln_VAR(w_ext, cplx2d::extend_w_edges_to_all_faces(w));
+// debug::println("w_ext:", w_ext);
+
+// mln_VAR(is_line, pw::value(w_ext) == pw::cst(0));
+// debug::println("w line:", w_ext | is_line);
+ }
+
+ // accu::count< util::pix<g_t> > a_;
+ accu::height<g_t> a_;
+
+ compute_attribute_extincted(g, cplx2d::e2e(), a_,
+ w);
+
}
Index: theo/esiee/jean/pfg3d.cc
--- theo/esiee/jean/pfg3d.cc (revision 3230)
+++ theo/esiee/jean/pfg3d.cc (working copy)
@@ -70,7 +70,7 @@
{
using namespace mln;
- box3d b = make::box3d(-1,1, -1,1, -1,1);
+ box3d b = make::box3d(-1,-1,-1, +1,+1,+1);
image3d<unsigned> ima(b);
debug::iota(ima);
debug::println(ima);