From: Maxime van Noppen <yabo(a)lrde.epita.fr>
To: olena-patches(a)lrde.epita.fr
Subject: r2714: Compute volume of max tree nodes
URL:
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
ChangeLog:
2008-10-28 Maxime van Noppen <yabo(a)lrde.epita.fr>
Compute volume of max tree nodes.
* Makefile: Little fix.
* max_tree.hh: Compute the volume.
* v2.cc: Call the volume routine.
---
Makefile | 3 ++-
max_tree.hh | 45 +++++++++++++++++++++++++++++++++++++++++++--
v2.cc | 2 ++
3 files changed, 47 insertions(+), 3 deletions(-)
Index: branches/cleanup-2008/milena/sandbox/classif/max_tree.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/classif/max_tree.hh (revision 2713)
+++ branches/cleanup-2008/milena/sandbox/classif/max_tree.hh (revision 2714)
@@ -9,6 +9,7 @@
# include <mln/level/sort_psites.hh>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/core/alias/neighb2d.hh>
# include <mln/value/int_u8.hh>
# include <mln/io/pgm/load.hh>
@@ -33,9 +34,13 @@
mln_ch_value(I, point) parent;
mln_ch_value(I, point) zpar;
+ // image of volumes
+ image3d<unsigned> vol;
+ image3d<unsigned> nb_represent;
+ image3d<double> density;
+
max_tree_(const I& f, const N& nbh)
- : f(f),
- nbh(nbh)
+ : f(f), nbh(nbh), vol(f.domain()), nb_represent(f.domain()), density(f.domain())
{
run();
}
@@ -98,6 +103,42 @@
debug::println(area);
}
+ void volume()
+ {
+ level::fill(vol, 0);
+ level::fill(nb_represent, 0);
+
+ {
+ mln_fwd_piter(S) p(s);
+
+ for_all(p)
+ {
+ vol(p) += 1;
+ nb_represent(p) += f(p);
+
+ if (parent(p) != p)
+ {
+ nb_represent(parent(p)) += nb_represent(p);
+ vol(parent(p)) += vol(p);
+ }
+
+ density(p) = nb_represent(p) / (double) vol(p);
+ }
+ }
+
+ {
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ {
+ std::cerr << " Color " << p << std::endl
+ << " vol = " << vol(p) << "
vertices" << std::endl
+ << " nb_represent = " << nb_represent(p) <<
std::endl
+ << " f = " << f(p) << std::endl
+ << " density = " << density(p) << "
representant / vertices " << std::endl << std::endl;
+ }
+ }
+ }
+
bool is_root(const point& p) const
{
return parent(p) == p;
Index: branches/cleanup-2008/milena/sandbox/classif/v2.cc
===================================================================
--- branches/cleanup-2008/milena/sandbox/classif/v2.cc (revision 2713)
+++ branches/cleanup-2008/milena/sandbox/classif/v2.cc (revision 2714)
@@ -55,6 +55,8 @@
out(p) = value::rgb8(pn[0] * f, pn[1] * f, pn[2] * f);
}
io::ppm::save(out, "tmp.ppm");
+
+ run.volume();
}
bool usage(int argc, char ** argv)
Index: branches/cleanup-2008/milena/sandbox/classif/Makefile
===================================================================
--- branches/cleanup-2008/milena/sandbox/classif/Makefile (revision 2713)
+++ branches/cleanup-2008/milena/sandbox/classif/Makefile (revision 2714)
@@ -13,7 +13,7 @@
# V2
V2_INCLUDES=-I../.. -I../garrigues/fllt
-V2_SRC=v2.cc
+V2_SRC=v2.cc max_tree.hh
V2=v2
V2_DBG=v2_dbg
@@ -43,6 +43,7 @@
rm -f $(ICCVG_DBG)
rm -f $(V2)
rm -f $(V2_DBG)
+ rm -f *.log
check-debug: $(ICCVG_DBG)
./iccvg_dbg $(IMG) $(DIV) $(LAMBDA) $(LOG)