https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update n_cmpt3.
* jardonnet/n_cmpt/n_cmpt3.hh: Update cmpts--.
* jardonnet/n_cmpt/n_cmpt3.cc: Try to use 1d image.
n_cmpt3.cc | 7 ++++++-
n_cmpt3.hh | 35 ++++++++++++++++-------------------
2 files changed, 22 insertions(+), 20 deletions(-)
Index: jardonnet/n_cmpt/n_cmpt3.hh
--- jardonnet/n_cmpt/n_cmpt3.hh (revision 2998)
+++ jardonnet/n_cmpt/n_cmpt3.hh (working copy)
@@ -61,19 +61,6 @@
return parent(x) = find_root(parent, parent(x));
}
- template < typename I >
- unsigned count_minima(const I& ima)
- {
- unsigned cmpt = 0;
- mln_piter(I) p(ima.domain());
- for_all(p)
- {
- if (ima(p) != literal::zero)
- cmpt++;
- }
- return cmpt;
- }
-
template < typename I, typename N>
I
n_cmpt3(const I& ima, const N& nbh,
@@ -91,7 +78,7 @@
// compute volume image
typedef p_array<mln_psite(I)> S;
- typedef image2d<unsigned> V;
+ typedef mln_ch_value(I,unsigned) V;
typedef accu::volume<I> A;
S sp = level::sort_psites_decreasing(ima);
@@ -152,20 +139,30 @@
P r = find_root(parent, n);
if (r != p)
{
+ // One cmpt less if
+ if (volume(r) != volume(p)) // r and p have differerent volumes
+ if (not volume_set(p).is_empty()) // r already belong to a cmpt
+ if (volume_set(p) != volume_set(r)) // cmpt r and p are different
+ if (cmpts > lambda) // union is still alowed
+ cmpts--;
+
+ if (cmpts > lambda ||
+ volume(r) == volume(p) ||
+ volume_set(p).is_empty())
+ {
+ parent(r) = p;
// propagate set
volume_set(p).insert(volume_set(r));
- // build tree
- parent(r) = p;
+ }
}
}
}
deja_vu(p) = true;
}
- debug::println(volume_set);
-
step2:
-// std::cout << "Nb cmpts after processing : " << cmpts
<< std::endl;
+ debug::println(volume_set);
+ std::cout << "Nb cmpts after processing : " << cmpts <<
std::endl;
// second pass
I output(ima.domain());
Index: jardonnet/n_cmpt/n_cmpt3.cc
--- jardonnet/n_cmpt/n_cmpt3.cc (revision 2998)
+++ jardonnet/n_cmpt/n_cmpt3.cc (working copy)
@@ -5,6 +5,8 @@
#include <mln/core/alias/neighb2d.hh>
#include <mln/value/int_u8.hh>
+#include <mln/make/image.hh>
+
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
@@ -32,6 +34,9 @@
io::pgm::load(ima, argv[1]);
unsigned lambda = atoi(argv[2]);
- io::pgm::save(n_cmpt::n_cmpt3(ima, c4(), lambda),
+ int_u8 tab[] = {2,3,1,0,2,3,2,2,1};
+ image1d<int_u8> ima1= make::image(tab);
+
+ io::pgm::save(n_cmpt::n_cmpt3(ima1, c4(), lambda),
"out.pgm");
}