https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Check correct filtering.
* jardonnet/n_cmpt/n_cmpt3.hh: Update, Fix, Remove.
* jardonnet/n_cmpt/test3.cc: Volume closing.
n_cmpt3.hh | 91 ++++++++++++++++++++++++++++---------------------------------
test3.cc | 36 ++++++++++++++++++++++++
2 files changed, 78 insertions(+), 49 deletions(-)
Index: jardonnet/n_cmpt/n_cmpt3.hh
--- jardonnet/n_cmpt/n_cmpt3.hh (revision 2982)
+++ jardonnet/n_cmpt/n_cmpt3.hh (working copy)
@@ -50,21 +50,6 @@
# ifndef MLN_INCLUDE_ONLY
template<typename I>
- mln_ch_value(I, util::set<mln_psite(I)>)
- minima_sets(const I& ima)
- {
- mln_ch_value(I, util::set<mln_psite(I)>) ima_set(ima.domain());
-
- mln_piter(I) p(ima.domain());
- for_all(p)
- {
- if (ima(p) != literal::zero)
- ima_set(p).insert(p);
- }
- return ima_set;
- }
-
- template <typename I>
inline
mln_psite(I)
find_root(I& parent,
@@ -96,6 +81,8 @@
{
unsigned label;
+ debug::println(ima);
+
// get /ima/ regional minima
mln_ch_value(I, unsigned) min = labeling::regional_minima(ima, nbh, label);
std::cout << "/ima/ regional minima" << std::endl;
@@ -105,9 +92,12 @@
typedef p_array<mln_psite(I)> S;
typedef image2d<unsigned> V;
typedef accu::volume<I> A;
+
S sp = level::sort_psites_decreasing(ima);
morpho::tree::data<I,S> t(ima, sp, nbh);
V volume = morpho::tree::compute_attribute_image(A(), t);
+ sp = level::sort_psites_increasing(volume);
+ debug::println(volume);
// get /volume/ regional minima
mln_ch_value(I, unsigned) min_v = labeling::regional_minima(volume, nbh, label);
@@ -117,38 +107,39 @@
// tester minima de ima == minima de attr
//mln_assertion(min == min_v);
- mln_ch_value(I, util::set<mln_psite(I)>) volume_set = minima_sets(volume);
+ mln_ch_value(I, util::set<unsigned>) volume_set;
+ initialize(volume_set, min_v);
// number of minima
- int cmpts = count_minima(min_v);
+ int cmpts = label;
std::cout << "Nb of regionnal minima : " << cmpts <<
std::endl;
// prepare union find
typedef mln_psite(V) P;
//data
- mln_ch_value(V, accu::volume<V>) data;
- initialize(data, volume);
+ mln_ch_value(V, accu::volume<V>) data(volume.domain());
//deja_vu
- mln_ch_value(V, bool) deja_vu;
- initialize(deja_vu, volume);
+ mln_ch_value(V, bool) deja_vu(volume.domain());
mln::level::fill(deja_vu, false);
//parent
- mln_ch_value(V, P) parent;
- initialize(parent, volume);
+ mln_ch_value(V, P) parent(volume.domain());
{
mln_fwd_piter(S) p(sp);
for_all(p)
+ {
parent(p) = p;
+ if (min_v(p) != 0) // p in a reg min of the attribute image
+ volume_set(p).insert(min_v(p));
+ }
}
+ debug::println(volume_set);
// union find sur volume
mln_fwd_piter(S) p(sp);
mln_niter(N) n(nbh, p);
for_all(p)
{
- // Make set.
- data(p).take_as_init(make::pix(volume, p));
for_all(n)
{
if (volume.domain().has(n) && deja_vu(n))
@@ -157,31 +148,30 @@
P r = find_root(parent, n);
if (r != p)
{
- if (volume(r) != volume(p) && (data(p).to_result() > lambda))
- {
- data(p).set_value(lambda);
- continue;
- }
-
- if (volume(r) != volume(p))
- {
- std::cout << "1: volume"<<r<<" !=
volume"<<p<<"" << " with data"<<p<<
" = " <<
- data(p).to_result() << std::endl;
- if (not volume_set(p).is_empty())
- {
- std::cout << "2: not
volume_set"<<p<<".is_empty()" << std::endl;
- if (volume_set(p) != volume_set(r))
- {
- std::cout << "3: volume_set"<<p<<"
!= volume_set"<<r<< std::endl;
- cmpts--;
- }
- }
- }
+ if (volume(p) > lambda)
+ goto step2;
+// if (volume(r) != volume(p) && (data(p).to_result() > lambda))
+// {
+// data(p).set_value(lambda);
+// continue;
+// }
+
+// if (volume(r) != volume(p))
+// {
+// std::cout << "1: volume"<<r<<" !=
volume"<<p<<"" << " with data"<<p<<
" = " <<
+// data(p).to_result() << std::endl;
+// if (not volume_set(p).is_empty())
+// {
+// std::cout << "2: not
volume_set"<<p<<".is_empty()" << std::endl;
+// if (volume_set(p) != volume_set(r))
+// {
+// std::cout << "3:
volume_set"<<p<<" != volume_set"<<r<< std::endl;
+// cmpts--;
+// }
+// }
+// }
// propagate set
volume_set(p).insert(volume_set(r));
- assert(data(p).to_result() != 0);
- // propagate attribute
- data(p).take(data(r));
// build tree
parent(r) = p;
}
@@ -190,7 +180,9 @@
deja_vu(p) = true;
}
- std::cout << "Nb cmpts after processing : " << cmpts <<
std::endl;
+ debug::println(volume_set);
+ step2:
+// std::cout << "Nb cmpts after processing : " << cmpts
<< std::endl;
// second pass
I output(ima.domain());
@@ -202,6 +194,7 @@
else
output(p) = output(parent(p));
}
+
return output;
}
Index: jardonnet/n_cmpt/test3.cc
--- jardonnet/n_cmpt/test3.cc (revision 0)
+++ jardonnet/n_cmpt/test3.cc (revision 0)
@@ -0,0 +1,36 @@
+
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/morpho/closing_volume.hh>
+
+using namespace mln;
+using namespace mln::value;
+
+bool usage(int argc, char ** argv)
+{
+ if (argc != 3)
+ {
+ std::cout << argv[0] << " ima.pgm lambda" << std::endl;
+ return false;
+ }
+ return true;
+}
+
+int main(int argc, char ** argv)
+{
+ if (not usage(argc,argv))
+ return 1;
+
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[1]);
+ unsigned lambda = atoi(argv[2]);
+
+ io::pgm::save(morpho::closing_volume(ima, c4(), lambda),
+ "out.pgm");
+}