From: Maxime van Noppen <yabo(a)lrde.epita.fr>
To: olena-patches(a)lrde.epita.fr
Subject: r2723: Implement a simple filter on the max_tree
URL:
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
ChangeLog:
2008-10-29 Maxime van Noppen <yabo(a)lrde.epita.fr>
Implement a simple filter on the max_tree.
* Makefile: Add nice rules.
* max_tree.hh: Add to_ppm, compute_mean_colors and number_of_nodes.
* v2.cc: Fix the getopt.
---
Makefile | 9 ++++++
max_tree.hh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
v2.cc | 21 ++++++++++-----
3 files changed, 105 insertions(+), 7 deletions(-)
Index: branches/cleanup-2008/milena/sandbox/classif/max_tree.hh
===================================================================
--- branches/cleanup-2008/milena/sandbox/classif/max_tree.hh (revision 2722)
+++ branches/cleanup-2008/milena/sandbox/classif/max_tree.hh (revision 2723)
@@ -12,9 +12,11 @@
# include <mln/core/image/image3d.hh>
# include <mln/core/alias/neighb2d.hh>
# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
# include <mln/io/pgm/load.hh>
# include <mln/core/site_set/p_array.hh>
# include <mln/debug/println.hh>
+# include <mln/io/ppm/save.hh>
using namespace mln;
@@ -39,8 +41,13 @@
image3d<unsigned> nb_represent;
image3d<double> density;
+ //tags
+ image3d<bool> is_active;
+ image3d< algebra::vec<3, double> > mean_color;
+
max_tree_(const I& f, const N& nbh)
- : f(f), nbh(nbh), vol(f.domain()), nb_represent(f.domain()), density(f.domain())
+ : f(f), nbh(nbh), vol(f.domain()), nb_represent(f.domain()), density(f.domain()),
+ is_active(f.domain()), mean_color(f.domain())
{
run();
}
@@ -139,6 +146,79 @@
}
}
+ void compute_mean_color()
+ {
+ level::fill(mean_color, make::vec(0, 0, 0));
+
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ mean_color(p) = make::vec(p[0], p[1], p[2]);
+
+ for_all(p)
+ mean_color(parent(p)) = (mean_color(parent(p)) + mean_color(p)) / 2.;
+ }
+
+ void simple_filter_1(int lambda)
+ {
+ level::fill(is_active, true);
+
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ {
+ if (vol(p) < lambda)
+ is_active(p) = false;
+ }
+ }
+
+ template < typename J >
+ void to_ppm(const J& ima, const std::string& file, unsigned f)
+ {
+ J out(ima.domain());
+ level::fill(out, value::rgb8(0, 0, 0));
+
+ mln_piter(J) p(ima.domain());
+ for_all(p)
+ {
+ point3d p3 = point3d(ima(p).red() / f, ima(p).green() / f, ima(p).blue() / f);
+
+ point3d node = p3;
+ if (not is_node(p3))
+ {
+ if (is_active(parent(p3)))
+ goto write;
+
+ node = parent(p3);
+ }
+
+ while (not is_active(node))
+ node = parent(node);
+
+write:
+ out(p) = value::rgb8(static_cast<unsigned char>(mean_color(node)[0] * f),
+ static_cast<unsigned char>(mean_color(node)[1] * f),
+ static_cast<unsigned char>(mean_color(node)[2] * f));
+ //out(p) = value::rgb8(mean_color(node)[0] * f, mean_color(node)[1] * f,
mean_color(node)[2] * f);
+ }
+
+ io::ppm::save(out, file);
+ }
+
+ unsigned number_of_nodes()
+ {
+ p_array<point> node;
+
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ if (is_node(p))
+ node.insert(p);
+
+ std::cout << s.nsites() << std::endl;
+ std::cout << parent.domain().nsites() << std::endl;
+ std::cout << node.nsites() << std::endl;
+
+ return s.nsites();
+ }
+
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 2722)
+++ branches/cleanup-2008/milena/sandbox/classif/v2.cc (revision 2723)
@@ -24,7 +24,7 @@
mln::image3d<unsigned>
fill_histo(const I& ima, int f)
{
- const value::int_u8 v = 255 / f; // FIXME
+ const value::int_u8 v = 256 / f; // FIXME
image3d<unsigned> histo(v,v,v);
level::fill(histo, 0);
unsigned i = 0;
@@ -40,10 +40,10 @@
template <typename I, typename J, typename N>
unsigned
-compute_max_tree(const I& ima, const J& histo, const N& nbh, const unsigned
f)
+compute_max_tree(const I& ima, const J& histo, const N& nbh, const unsigned
f, int lambda)
{
max_tree_<J,N> run(histo, nbh);
-
+#if 0
I out(ima.domain());
mln_piter(I) p(ima.domain());
for_all(p)
@@ -55,15 +55,22 @@
out(p) = value::rgb8(pn[0] * f, pn[1] * f, pn[2] * f);
}
io::ppm::save(out, "tmp.ppm");
+#endif
+ //run.number_of_nodes();
run.volume();
+ run.simple_filter_1(lambda);
+ run.compute_mean_color();
+ run.to_ppm(ima, "out.ppm", f);
+
+ //std::cout << " Number of nodes : " << run.number_of_nodes()
<< std::endl;
}
bool usage(int argc, char ** argv)
{
- if (argc != 3)
+ if (argc != 4)
{
- std::cout << "usage: " << argv[0] << " image
div_factor" << std::endl;
+ std::cout << "usage: " << argv[0] << " image
div_factor lambda" << std::endl;
return false;
}
return true;
@@ -73,9 +80,11 @@
{
if (not usage(argc, argv))
return 1;
+
image2d<value::rgb8> ima;
ima = io::ppm::load<value::rgb8>(argv[1]);
const int div_factor = atoi(argv[2]);
+ const int lambda = atoi(argv[3]);
//make histo
image3d<unsigned> histo = fill_histo(ima,div_factor);
@@ -87,5 +96,5 @@
//debug::println(phisto);
// Compute max_tree
- compute_max_tree(ima, histo, c6(), div_factor);
+ compute_max_tree(ima, histo, c6(), div_factor, lambda);
}
Index: branches/cleanup-2008/milena/sandbox/classif/Makefile
===================================================================
--- branches/cleanup-2008/milena/sandbox/classif/Makefile (revision 2722)
+++ branches/cleanup-2008/milena/sandbox/classif/Makefile (revision 2723)
@@ -55,9 +55,18 @@
cat stdout.log
$(DISP) out.ppm &
+v2-check: $(V2)
+ ./v2 $(IMG) $(DIV) $(LAMBDA) $(LOG)
+ cat stdout.log
+ $(DISP) out.ppm &
+
valgrind: $(ICCVG_DBG)
valgrind --log-file=valgrind.log ./iccvg_dbg ../../img/lena.ppm $(DIV) $(LAMBDA) $(LOG)
gdb: $(ICCVG_DBG)
echo "run ../../img/lena.ppm $(DIV) $(LAMBDA)" > gdb.cmd
gdb $(ICCVG_DBG) -x gdb.cmd
+
+v2-gdb: $(V2_DBG)
+ echo "run ../../img/lena.ppm $(DIV) $(LAMBDA) $(LOG)" > gdb.cmd
+ gdb $(V2_DBG) -x gdb.cmd