URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-11 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Plot labels in fixed watershed.
* fabien/igr/plot_label.hh: Implement plot_label() for
fixed segmentation.
* fabien/igr/seg_fixed.cc: Add plot_label() calls.
---
plot_label.hh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
seg_fixed.cc | 43 ++++++++++++++++++++++++++++++++++++-------
2 files changed, 94 insertions(+), 7 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/seg_fixed.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3782)
+++ trunk/milena/sandbox/fabien/igr/seg_fixed.cc (revision 3783)
@@ -25,7 +25,9 @@
#include <mln/data/paste.hh>
#include <mln/debug/quiet.hh>
#include <mln/convert/from_to.hh>
+#include <mln/labeling/wrap.hh>
#include <mln/level/compute.hh>
+#include <mln/level/convert.hh>
#include <mln/level/stretch.hh>
#include <mln/make/image2d.hh>
#include <mln/math/diff_abs.hh>
@@ -41,11 +43,13 @@
#include <mln/world/inter_pixel/compute.hh>
#include <mln/world/inter_pixel/immerse.hh>
#include <mln/world/inter_pixel/neighb2d.hh>
-#include <mln/world/inter_pixel/is_pixel.hh>
+#include <mln/world/inter_pixel/all.hh>
#include <mln/labeling/colorize.hh>
#include <mln/debug/println.hh>
+#include <mln/trace/quiet.hh>
+#include "plot_label.hh"
using namespace mln;
using value::int_u8;
@@ -152,7 +156,7 @@
// Dummy.
-///////////////////////////////////////////////////////////////////////////////
+//-------
template <typename I, typename N>
inline
image2d<int>
@@ -194,13 +198,14 @@
res += std::min(v1[i], v2[i]);
image1d<V> tmp_ima;
+ image1d<V> tmp_ima2;
accu::sum<V> accu_sum;
convert::from_to(v1, tmp_ima);
float sum_v1 = level::compute(accu_sum, tmp_ima);
- convert::from_to(v2, tmp_ima);
- float sum_v2 = level::compute(accu_sum, tmp_ima);
+ convert::from_to(v2, tmp_ima2);
+ float sum_v2 = level::compute(accu_sum, tmp_ima2);
res /= std::max(sum_v1, sum_v2);
@@ -282,10 +287,34 @@
L nbasins;
mln_VAR(wst, morpho::watershed::flooding(clo, world::inter_pixel::e2e(), nbasins));
- mln_VAR(w, wst.unmorph_());
- data::fill((w | (!world::inter_pixel::is_separator())).rw(), nbasins.next());
- io::ppm::save(labeling::colorize(value::rgb8(), w, nbasins.next()),
"result.ppm");
+ std::cout << "nbasins: " << nbasins << std::endl;
+
+
+ mln_VAR(w_all, wst.unmorph_());
+ //data::fill((w | (!world::inter_pixel::is_separator())).rw(), nbasins.next());
+ mln_VAR(w_pixels, w_all | world::inter_pixel::is_pixel());
+ data::paste(morpho::dilation(extend(w_pixels, pw::value(w_all)), c4().win()), w_all);
+ // edges -> dots
+ mln_VAR(w_dots, w_all | world::inter_pixel::dim2::is_dot());
+ data::paste(morpho::erosion(extend(w_dots, pw::value(w_all)), c4().win()), w_all);
+
+ //io::ppm::save(labeling::colorize(value::rgb8(), w, nbasins.next()),
"result.ppm");
+ io::pgm::save(labeling::wrap(int_u8(), w_all), "result_labels.pgm");
+
+ // Plots.
+ image2d<L> w_simple = world::inter_pixel::full2image(w_all);
+ plot_label(input, w_simple, 166u);
+ plot_label(input, w_simple, 182u);
+ plot_label(input, w_simple, 188u);
+ plot_label(input, w_simple, 189u);
+ plot_label(input, w_simple, 193u);
+ plot_label(input, w_simple, 195u);
+ plot_label(input, w_simple, 196u);
+ plot_label(input, w_simple, 198u);
+ plot_label(input, w_simple, 199u);
+ plot_label(input, w_simple, 200u);
+ plot_label(input, w_simple, 201u);
Index: trunk/milena/sandbox/fabien/igr/plot_label.hh
===================================================================
--- trunk/milena/sandbox/fabien/igr/plot_label.hh (revision 0)
+++ trunk/milena/sandbox/fabien/igr/plot_label.hh (revision 3783)
@@ -0,0 +1,58 @@
+#ifndef PLOT_LABEL_HH
+# define PLOT_LABEL_HH
+
+#include <iostream>
+#include <sstream>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/geom/bbox.hh>
+
+#include <mln/io/plot/save.hh>
+
+#include <mln/accu/mean.hh>
+#include <mln/accu/median_h.hh>
+#include <mln/level/compute.hh>
+#include <mln/pw/all.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+
+
+
+template <typename I, typename L, typename V>
+inline
+void plot_label(image3d<I>& ima, image2d<L>& ima_labels, V lbl)
+{
+ typedef image_if<image2d<L>,
mln::fun::eq_p2b_expr_<pw::value_<image2d<L> >, pw::cst_<V> > >
Lx;
+ Lx ima_label = ima_labels | pw::value(ima_labels) == pw::cst(lbl);
+ util::array<float> arr;
+ int sli_min = geom::bbox(ima).pmin().sli();
+ int sli_max = geom::bbox(ima).pmax().sli();
+
+ for (int sli = sli_min; sli <= sli_max; ++sli)
+ {
+ image2d<I> slice_ima = duplicate(slice(ima, sli));
+ accu::mean<I> accu_mean;
+ float mean = level::compute(accu_mean, slice_ima | ima_label.domain());
+ arr.append(mean);
+ }
+
+ std::ostringstream slabel;
+ slabel << "label_";
+ if (lbl < 100)
+ slabel << "0";
+ if (lbl < 10)
+ slabel << "0";
+ // FIXME: insert label location
+ slabel << lbl << ".plot";
+ io::plot::save(arr, slabel.str());
+}
+
+
+
+#endif // ! PLOT_LABEL_HH