URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update labeling_algo.
* labeling_algo.cc,
* labeling_algo.hh: Update.
---
labeling_algo.cc | 24 ++++++++++++--------
labeling_algo.hh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 78 insertions(+), 11 deletions(-)
Index: trunk/milena/sandbox/duhamel/labeling_algo.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1226)
+++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1227)
@@ -35,6 +35,7 @@
# include <mln/core/neighb2d.hh>
# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
+# include <mln/level/stretch.hh>
# include <mln/level/saturate.hh>
# include <mln/border/fill.hh>
# include <mln/io/pbm/load.hh>
@@ -51,32 +52,37 @@
using value::int_u8;
// image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
- image2d_b<bool> in = io::pbm::load("toto.pbm");
+ image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
- image2d_b<unsigned> lab(in.domain());
- image2d_b<unsigned> inte(in.domain());
+ image2d_b<int_u8> lab(in.domain());
+ image2d_b<int_u8> inte(in.domain());
image2d_b<int_u8> out(in.domain());
unsigned n;
- labeling::foreground(in, c4(), lab, n);
+ labeling::foreground(in, c8(), lab, n);
std::cout << "number of labels = " << n << std::endl;
std::vector<int_u8> vec;
image2d_b<int> input(in.domain());
+ // debug::println (in | make::box2d (100,100));
level::fill(input, lab);
+ lab(make::point2d (0,0)) = 0;
inte = make_algo(lab, c4 ());
border::fill (inte, 0);
image2d_b<int_u8> inte2(inte.domain());
- // level::fill(inte2, inte);
+ level::stretch (inte, inte2);
- level::saturate(inte, 1, 255, inte2);
- io::pgm::save(inte2, "inte.pgm");
- // debug::println_with_border(inte2);
+ io::pgm::save(inte, "inte.pgm");
+ io::pgm::save(inte2, "inte2.pgm");
- mesh_p<point2d> m = make::graph_with_no_border(inte2, c4());
+ debug::println(lab | make::box2d (30,30) );
+
+ // mesh_p<point2d> m = make::graph_with_no_border(inte, c4());
+
+ mesh_p<point2d> m = make::voronoi(inte, lab, c4());
std::cout << "OK" << std::endl;
draw::mesh (out, m, 255, 128);
Index: trunk/milena/sandbox/duhamel/labeling_algo.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1226)
+++ trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1227)
@@ -89,10 +89,71 @@
m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
}
- for (unsigned i = min; i <= max; ++i)
+ for (unsigned i = 0; i < nb; ++i)
{
gr.add_node ();
- v[i - min] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
+ v[i] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
+ (unsigned)tab_mean[i].to_result ()[1]);
+ }
+
+ typename std::map<std::pair<V, V>, bool>::const_iterator it = m.begin
();
+ for (; it != m.end (); ++it)
+ gr.add_edge((*it).first.first, (*it).first.second);
+
+ mesh_p<P> res(gr, v);
+ return res;
+ }
+
+
+ template <typename I, typename N>
+ mesh_p<mln_psite(I)>
+ voronoi (Image<I>& ima_,
+ Image<I>& orig_,
+ const Neighborhood<N>& nbh)
+ {
+ typedef metal::vec<2,float> X;
+ typedef mln_value(I) V;
+ typedef mln_psite(I) P;
+
+ I& ima = exact(ima_);
+ I& orig = exact(orig_);
+ util::graph<void> gr;
+ V min, max;
+ estim::min_max (ima, min, max);
+ unsigned nb = max - min + 1;
+ std::vector<P> v(nb);
+ std::vector< accu::mean_< X > > tab_mean (nb);
+ std::map<std::pair<V, V>, bool> m;
+
+ {
+ mln_piter(I) p(orig.domain());
+
+ for_all(p)
+ {
+ if (orig(p) != 0)
+ {
+ X x = mln_point(I)(p);
+ tab_mean[orig(p) - min].take(x);
+ }
+ }
+ }
+
+ {
+ mln_piter(I) p(ima.domain());
+ mln_niter(N) n(nbh, p);
+
+ for_all(p)
+ {
+ for_all (n) if (ima.has(n))
+ if (ima(p) != ima(n))
+ m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
+ }
+ }
+
+ for (unsigned i = 0; i < nb; ++i)
+ {
+ gr.add_node ();
+ v[i] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
(unsigned)tab_mean[i].to_result ()[1]);
}