https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
INIM: Classif: Final Upgrade.
* inim/classif/src/max_tree.hh: Fix comment.
* inim/classif/src/proj.hh: Add specific projection.
* inim/classif/src/v2.cc: Add efficient technique based
histo value merging.
max_tree.hh | 7 +++++--
proj.hh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
v2.cc | 50 ++++++++++++++++++++++++++++++++------------------
3 files changed, 91 insertions(+), 24 deletions(-)
Index: inim/classif/src/max_tree.hh
--- inim/classif/src/max_tree.hh (revision 2838)
+++ inim/classif/src/max_tree.hh (working copy)
@@ -153,6 +153,7 @@
return mean_color;
}
+ // Filter method
template<typename X>
void lumberjack(const X& ima, const mln_value(X)& lambda)
{
@@ -177,8 +178,9 @@
std::cout << std::endl;
}
+ // Fusion method
template<typename X>
- void nuclear_fusion(const X& ima, const mln_value(X)& lambda)
+ void nuclear_fusion(const X& ima, double lambda)
{
unsigned progress = 0;
unsigned step = s.nsites() / 100;
@@ -188,7 +190,8 @@
mln_fwd_piter(S) p(s);
for_all(p)
{
- if (fabs(1 - ima(new_parent(p)) / ima(p)) < lambda)
+ if (ima(p) != 0)
+ if (fabs(1. - ima(new_parent(p)) / (double) ima(p)) < lambda)
is_active(p) = false;
++progress;
Index: inim/classif/src/display.hh
Index: inim/classif/src/proj.hh
--- inim/classif/src/proj.hh (revision 2838)
+++ inim/classif/src/proj.hh (working copy)
@@ -35,6 +35,7 @@
#include <mln/accu/maj_h.hh>
#include <mln/literal/white.hh>
#include <mln/literal/colors.hh>
+#include <mln/make/vec.hh>
namespace mln
{
@@ -59,11 +60,11 @@
save_class(const image3d<T>& histo, const image3d<U>& ws,
K mean, const char * fn)
{
- accu::maj_h<value::int_u8> max_1;
- image2d<value::int_u8> hproj = proj(histo, max_1);
+ accu::maj_h<value::int_u8> maj_1;
+ image2d<value::int_u8> hproj = proj(histo, maj_1);
- accu::maj_h<value::int_u8> max_2;
- image2d<value::int_u8> proj_class = proj(ws, max_2);
+ accu::maj_h<value::int_u8> maj_2;
+ image2d<value::int_u8> proj_class = proj(ws, maj_2);
//std::cout << histo;
@@ -82,6 +83,55 @@
io::ppm::save(out, fn);
}
+ template <typename T, typename I, typename A>
+ image2d<mln_result(A)>
+ proj_vec(const image3d<T>& input, const I& histo, A)
+ {
+ image2d<A> acc(geom::nslis(input), geom::nrows(input));
+ mln_piter(image3d<T>) p(input.domain());
+ for_all(p) // 3d
+ if (histo(p) != literal::zero)
+ acc.at(p.sli(), p.row()).take(input(p));
+
+ image2d<mln_result(A)> output(acc.domain());
+ level::paste(acc, output);
+ return output;
+ }
+
+ template <typename I, typename T, typename U, typename V>
+ void
+ save_class_v2(const I& ima, const T& histo, image3d<U>& mean,
+ const image3d<V>& parent, unsigned f,
+ const char * fn)
+ {
+ image3d<value::rgb8> out3d(histo.domain());
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ {
+ point3d p3 = point3d(ima(p).red() / f,
+ ima(p).green() / f,
+ ima(p).blue() / f);
+ out3d(p3) = convert::to<value::rgb8>(mean(parent(p3)));
+ }
+
+ //FIXME: maj_h implies set is finite, mx set is ordered
+ accu::mean<mln::algebra::vec<3u, float> > maj_2;
+ image2d<mln::algebra::vec<3u, float> > mproj =
+ proj_vec(out3d, histo, maj_2);
+
+ image2d<value::rgb8> out(geom::nslis(histo), geom::nrows(histo));
+ level::fill(out, literal::white);
+
+ mln_piter(image2d<value::int_u8>) p1(out.domain());
+ for_all(p1)
+ {
+ out(p1) = convert::to<value::rgb8>(mproj(p1));
+ }
+
+ io::ppm::save(out, fn);
+ }
+
} // end of namespace mln
#endif /* MLN_PROJ_HH */
Index: inim/classif/src/v2.cc
--- inim/classif/src/v2.cc (revision 2838)
+++ inim/classif/src/v2.cc (working copy)
@@ -30,7 +30,6 @@
const value::int_u8 v = 256 / f; // FIXME
image3d<unsigned> histo(v,v,v);
level::fill(histo, 0);
- unsigned i = 0;
mln_piter(I) p(ima.domain());
for_all(p)
@@ -55,11 +54,11 @@
}
template <typename I, typename J, typename N>
-unsigned
+void
process_max_tree(const I& ima, const J& histo, const N& nbh,
- double density_lambda, unsigned volume_lambda,
- unsigned nb_represent_lambda, unsigned color_lambda,
- unsigned div_factor)
+ double density_lambda, double value_lambda,
+ unsigned volume_lambda, unsigned nb_represent_lambda,
+ unsigned color_lambda, unsigned div_factor)
{
max_tree_<J,N> run(histo, nbh);
@@ -70,13 +69,20 @@
image3d< algebra::vec<3, double> > mean_color =
run.compute_mean_color();
image3d<double> density = compute_density(nb_represent, volume);
- // Density closing
+ // Density fusion
if (density_lambda > 0.00001)
{
- std::cout << "Density cutting" << std::endl;
+ std::cout << "Density fusion" << std::endl;
run.nuclear_fusion(density, density_lambda);
}
+ // value fusion
+ if (value_lambda > 0.00001)
+ {
+ std::cout << "Value fusion" << std::endl;
+ run.nuclear_fusion(histo, value_lambda);
+ }
+
// Volume cutting
if (volume_lambda != 0)
{
@@ -115,7 +121,9 @@
for_all(p)
if (run.is_active(p))
{
- std::cerr << mean_color(p) << "\t\t" << nb_class <<
"\t\t" << density(p) << "\t\t" << volume(p) <<
"\t\t" << nb_represent(p) << std::endl;
+ std::cerr << mean_color(p) << "\t\t" << nb_class
+ << "\t\t" << density(p) << "\t\t"
<< volume(p)
+ << "\t\t" << nb_represent(p) << std::endl;
++nb_class;
}
@@ -125,13 +133,21 @@
// Write the image w.r.t. the max tree
run.to_ppm(ima, "out.ppm", div_factor, mean_color);
+
+ //proj
+ save_class_v2(ima, histo, mean_color, run.new_parent,
+ div_factor, "histo.ppm");
}
bool usage(int argc, char ** argv)
{
- if (argc != 7)
+ if (argc != 8)
{
- std::cout << "usage: " << argv[0] << " image
div_factor density_lambda volume_lambda nb_represent_lambda color_lambda" <<
std::endl;
+ std::cout << "usage: " << argv[0] << " image
div_factor "
+ << "density_lambda value_lambda volume_lambda "
+ << "nb_represent_lambda color_lambda" << std::endl;
+ std::cout << "Help: A value of 0 for any lambda means "
+ << "the related action won't be performed" <<
std::endl;
return false;
}
@@ -149,17 +165,15 @@
int div_factor = atoi(argv[2]);
float density_lambda = atof(argv[3]);
- unsigned volume_lambda = atoi(argv[4]);
- unsigned nb_represent_lambda = atoi(argv[5]);
- unsigned color_lambda = atoi(argv[6]);
+ float value_lambda = atof(argv[4]);
+ unsigned volume_lambda = atoi(argv[5]);
+ unsigned nb_represent_lambda = atoi(argv[6]);
+ unsigned color_lambda = atoi(argv[7]);
//make histo
image3d<unsigned> histo = fill_histo(ima, div_factor);
- //proj
- accu::mean<unsigned, unsigned, unsigned> mean;
- image2d<unsigned> phisto = proj(histo, mean);
-
// Process max_tree
- process_max_tree(ima, histo, c6(), density_lambda, volume_lambda, nb_represent_lambda,
color_lambda, div_factor);
+ process_max_tree(ima, histo, c6(), density_lambda, value_lambda,
+ volume_lambda, nb_represent_lambda, color_lambda, div_factor);
}