https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
Update nwst.
* jardonnet/n_cmpt/nwst.hh: Update. Mark local minima.
* jardonnet/n_cmpt/wst.cc: New. Add wst ref.
nwst.hh | 19 +++++++++++--------
wst.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 8 deletions(-)
Index: jardonnet/n_cmpt/nwst.hh
--- jardonnet/n_cmpt/nwst.hh (revision 3029)
+++ jardonnet/n_cmpt/nwst.hh (working copy)
@@ -81,9 +81,11 @@
// sort ima psites
typedef mln_psite(I) P;
typedef p_array<P> S;
- S sp = level::sort_psites_decreasing(ima);
-
+ S sp = level::sort_psites_increasing(ima);
+ // init watershed image
+ mln_ch_value(I, value::rgb8) wst(ima.domain());
+ mln::level::fill(wst, literal::black);
// number of minima
unsigned cmpts = label;
@@ -107,7 +109,10 @@
{
parent(p) = p;
if (min(p) != 0) // p in a reg min of the attribute image
+ {
fused(p) = true; // ok
+ wst(p) = literal::red;
+ }
}
}
@@ -115,10 +120,6 @@
std::cout << cmpts << " : ";
std::cout << std::endl;
- // init watershed image
- mln_ch_value(I, value::rgb8) wst(ima.domain());
- mln::level::fill(wst, literal::black);
-
// union find
mln_fwd_piter(S) p(sp);
mln_niter(N) n(nbh, p);
@@ -138,8 +139,6 @@
if (cmpts >= lambda) // union is still alowed
if (fused(p)) // p already belong to a cmpt (fused for an another n)
cmpts--;
- else
- wst(p) = literal::red;
if (cmpts >= lambda ||
ima(r) == ima(p) ||
@@ -156,6 +155,10 @@
std::cout << "ima " << ima(p) << " -
" << cmpts << std::endl;
debug::println(fused);
}
+
+ // mark limit point
+ if (parent(p) != parent(n))
+ wst(p) = literal::red;
}
}
}
Index: jardonnet/n_cmpt/wst.cc
--- jardonnet/n_cmpt/wst.cc (revision 0)
+++ jardonnet/n_cmpt/wst.cc (revision 0)
@@ -0,0 +1,46 @@
+
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/make/image.hh>
+#include <mln/core/alias/neighb1d.hh>
+
+#include <mln/morpho/meyer_wst.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include "nwst.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]);
+
+ ima(point2d(0,3)) = 106;
+
+ int_u8 label;
+ io::pgm::save(morpho::meyer_wst(ima, c4(), label),
+ "meyer_wst.ppm");
+ std::cout << label << std::endl;
+}