* green/demo/labeling/regional_maxima/regional_maxima.cc
(demo_17_12_2009): New function that describes the experimentation.
---
milena/sandbox/ChangeLog | 7 +
.../labeling/regional_maxima/regional_maxima.cc | 702 ++++++++++----------
2 files changed, 367 insertions(+), 342 deletions(-)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 3a7ffb7..8a92218 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-23 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Experiment variation on regional maxima labeling.
+
+ * green/demo/labeling/regional_maxima/regional_maxima.cc
+ (demo_17_12_2009): New function that describes the experimentation.
+
2009-12-18 Yann Jacquelet<jacquelet(a)lrde.epita.fr>
Fix the right behaviour of the regmax software.
diff --git a/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
b/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
index 65b6608..566c698 100644
--- a/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
+++ b/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
@@ -2,6 +2,7 @@
#include <iostream>
#include <sstream>
+#include <fstream>
#include <boost/format.hpp>
#include <mln/img_path.hh>
@@ -144,182 +145,6 @@ unsigned unquant(const float& value)
return result;
}
-template <unsigned n>
-void print_count2(const mln::image2d<mln::value::rgb<n> >& input_rgbn,
- const mln::image3d<unsigned>& histo,
- const mln::image3d<mln::value::label_8>& label,
- const unsigned n_labels)
-{
- typedef mln::value::label_8 t_lbl8;
- typedef mln::value::rgb<n> t_rgbn;
- typedef mln::value::int_u<n> t_int_un;
- typedef mln::algebra::vec<3,float> t_vec3f;
- typedef mln::accu::math::sum<unsigned,unsigned> t_sum;
- typedef mln::accu::stat::mean<t_vec3f,t_vec3f,t_vec3f> t_mean;
- typedef mln::accu::math::sum<t_vec3f,t_vec3f> t_diff;
- typedef mln::accu::stat::variance<float,float,float> t_var;
- typedef mln::image2d<t_lbl8> t_image2d_lbl8;
- typedef mln::image2d<t_rgbn> t_image2d_rgbn;
- typedef mln::image2d<t_int_un> t_image2d_int_un;
-
- mln::util::array<t_mean> mean((unsigned)(n_labels)+1);
-// mln::util::array<t_diff> diff((unsigned)(n_labels)+1);
- mln::util::array<t_var> var_red((unsigned)(n_labels)+1);
- mln::util::array<t_var> var_green((unsigned)(n_labels)+1);
- mln::util::array<t_var> var_blue((unsigned)(n_labels)+1);
- mln::util::array<t_sum> count((unsigned)(n_labels)+1);
- mln::util::array<float> abs((unsigned)(n_labels)+1);
- mln::util::array<float> rel((unsigned)(n_labels)+1);
- unsigned nb = 0;
-
- for (unsigned i = 0; i <= n_labels; ++i)
- {
- count(i).init();
- mean(i).init();
-// diff(i).init();
- var_red(i).init();
- var_green(i).init();
- var_blue(i).init();
- abs[i] = 0.0;
- rel[i] = 0.0;
- }
-
- mln::labeling::compute(count, histo, label, n_labels);
-
- for (unsigned i = 0; i <= n_labels; ++i)
- {
- unsigned c = count[i];
- nb += c;
- }
-
- for (unsigned i = 0; i <= n_labels; ++i)
- if (0 < count[i])
- {
- abs[i] = ((float)count[i] / nb)*100.0;
- rel[i] = ((float)count[i] / (nb - count[0]))*100.0;
- }
-
- t_image2d_lbl8 label_img = mln::data::transform(input_rgbn,
- t_labeling_rgbn<n>(label));
-
- mln::labeling::compute(mean, input_rgbn, label_img, n_labels);
-
-
-// t_image2d_rgbn mean_rgbn = mln::labeling::mean_values(input_rgbn,
-// label_img,
-// n_labels);
-
-// t_image2d_int_un mean_red =mln::data::transform(mean_rgbn,t_channel<n>());
-// t_image2d_int_un mean_green=mln::data::transform(mean_rgbn,t_channel<n>());
-// t_image2d_int_un mean_blue =mln::data::transform(mean_rgbn,t_channel<n>());
-
- t_image2d_int_un input_red =mln::data::transform(input_rgbn,
- t_channel<n,0>());
- t_image2d_int_un input_green=mln::data::transform(input_rgbn,
- t_channel<n,1>());
- t_image2d_int_un input_blue =mln::data::transform(input_rgbn,
- t_channel<n,2>());
-
-// FIXME VARIANCE NEGATIVE DANS LES RESULTATS !!
-
-// mln::labeling::compute(var_red, input_rgbn, label_img, n_labels);
-// mln::labeling::compute(var_green, input_rgbn, label_img, n_labels);
-// mln::labeling::compute(var_blue, input_rgbn, label_img, n_labels);
-
-// t_image2d_rgbn diff_rgbn = mln::arith::diff_abs(input_rgbn, mean_rgbn);
-
- std::cout << mln::labeling::compute(var_red, input_red, label_img,
n_labels)(29) << std::endl;
-// mln::labeling::compute(t_var(), input_red, label_img, n_labels);
- mln::labeling::compute(var_green, input_green, label_img, n_labels);
- mln::labeling::compute(var_blue, input_blue, label_img, n_labels);
-
- for (unsigned i = 0; i <= n_labels; ++i)
- {
- if (5.0 < abs[i] && 10.0 < rel[i])
- {
- const t_vec3f& mean_v = mean[i];
-// const t_vec3f& diff_v = diff[i];
-
- std::cout << i << " :[" << unquant<n>(mean_v[0])
-// << "(" << diff_v[0]
- << "(" << var_red[i]
- << ")," << unquant<n>(mean_v[1])
-// << "(" << diff_v[1]
- << "(" << var_green[i]
- << ")," << unquant<n>(mean_v[2])
-// << "(" << diff_v[2]
- << "(" << var_blue[i]
- << ")]- " << count[i]
- << " - " << abs[i]
- << " - " << rel[i]
- << std::endl;
- }
- }
-}
-
-
-void print_count(const mln::image3d<unsigned>& histo,
- const mln::image3d<mln::value::label_8>& label,
- const unsigned n_labels)
-{
- unsigned count[255];
- unsigned red[255];
- unsigned green[255];
- unsigned blue[255];
- unsigned nb = 0;
- unsigned tmp = 0;
-
- for (unsigned i = 0; i <= n_labels; ++i)
- {
- count[i] = 0;
- red[i] = 0;
- green[i] = 0;
- blue[i] = 0;
- }
-
- mln_piter_(mln::image3d<unsigned>) p(histo.domain());
-
- for_all(p)
- {
- count[label(p)] += histo(p);
- red[label(p)] += histo(p) * p.row();
- green[label(p)] += histo(p) * p.col();
- blue[label(p)] += histo(p) * p.sli();
- nb += histo(p);
- ++tmp;
- }
-
- std::cout << std::endl;
-
- std::cout << "nb : " << nb << std::endl;
- std::cout << "tmp : " << tmp << std::endl;
-
- std::cout << std::endl;
-
- for (unsigned i = 0; i <= n_labels; ++i)
- if (0 < count[i])
- {
- float percentage_abs = ((float)count[i] / nb)*100.0;
- float percentage_rel = ((float)count[i] / (nb - count[0]))*100.0;
-
- red[i] = red[i] / count[i];
- green[i] = green[i] / count[i];
- blue[i] = blue[i] / count[i];
-
- std::cout << "count[" << i << "]("
- << red[i] << ", " << green[i] << ", "
- << blue[i] << ") = " << count[i] << "("
- << percentage_abs << "%)";
-
- if (0 < i)
- std::cout << "[" << percentage_rel << "%]";
-
- std::cout << std::endl;
- }
-
- std::cout << std::endl;
-}
-
// Version optimisée de merge
template <unsigned n>
@@ -354,111 +179,98 @@ struct t_merge_lbl8_with_rgbn : mln::Function_v2v<
t_merge_lbl8_with_rgbn<n> >
}
};
-// version non optimisée de merge
-template <unsigned n>
-mln::image2d< mln::value::rgb<n> >
-merge(const mln::image2d< mln::value::rgb<n> >& input,
- const mln::image3d< mln::value::label_8 >& label)
-{
- mln::image2d<mln::value::rgb<n> > output;
- mln::initialize(output, input);
- // mln::data::fill(output, mln::literal::green);
+void compute_stats(const mln::image2d<mln::value::rgb8>& i_input_rgb8,
+ const mln::image2d<mln::value::label_8>& l_input_lbl8,
+ const mln::image3d<unsigned>& h_histo_rgbn,
+ const mln::image3d<mln::value::label_8>& l_histo_lbl8,
+ const mln::value::label_8& n_labels,
+ const std::string& log)
+{
+ typedef mln::algebra::vec<3,float> t_vec3f;
+ typedef mln::accu::math::sum<unsigned,unsigned> t_sum;
+ typedef mln::accu::stat::mean<t_vec3f,t_vec3f,t_vec3f> t_mean;
+ typedef mln::util::array<unsigned> t_count_array;
+ typedef mln::util::array<t_vec3f> t_mean_array;
- mln_piter(mln::image2d< mln::value::rgb<n> >) pi(input.domain());
- mln_piter(mln::image2d< mln::value::rgb<n> >) po(output.domain());
+ mln::util::array<float> abs((unsigned)(n_labels)+1);
+ mln::util::array<float> rel((unsigned)(n_labels)+1);
+ unsigned nb = 0;
- for_all_2(pi, po)
+ for (unsigned i = 0; i <= n_labels; ++i)
{
- const mln::value::rgb<n>& vi = input(pi);
- mln::value::rgb<n>& vo = output(po);
-
- if (0 < mln::opt::at(label,vi.blue(),vi.red(),vi.green()))
- {
- vo.red() = vi.red();
- vo.green() = vi.green();
- vo.blue() = vi.blue();
- }
- else
- vo = mln::literal::black;
+ abs[i] = 0.0;
+ rel[i] = 0.0;
}
- return output;
-}
-
-
-//
-// Theo regional maxima image processing chain.
-//
-
-// FIXME C'est la dilatation qui fait apparaître des classes < min_volume.
-// Une couleur se dilate au détriment du fond et des autres couleurs.
-
-int main2()
-{
- const unsigned min_volume = 1000;
- //const std::string& image = OLENA_IMG_PATH"/fly.ppm";
- const std::string& image = SCRIBO_PPM_IMG_PATH"/mp00082c_50p.ppm";
- //const std::string& image = OLENA_IMG_PATH"/tiny.ppm";
-
- typedef mln::value::label_8 t_lbl8;
- typedef mln::value::rgb8 t_rgb8;
- typedef mln::value::rgb<5> t_rgb5;
- typedef mln::image2d<t_rgb8> t_image2d_rgb8;
- typedef mln::image2d<t_rgb5> t_image2d_rgb5;
- typedef mln::image3d<t_lbl8> t_image3d_lbl8;
- typedef mln::image3d<unsigned> t_image3d_unsigned;
- typedef mln::fun::v2v::rgb8_to_rgbn<5> t_rgb8_to_rgb5;
- typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
- typedef mln::accu::math::sum<unsigned,unsigned> t_sum;
-
- mln::util::timer timer;
-
- // START IMAGE PROCESSING CHAIN
- timer.start();
-
- t_image2d_rgb8 input_rgb8;
- t_image2d_rgb5 input_rgb5;
- t_image3d_unsigned histo;
- t_image3d_unsigned opened;
- t_image3d_lbl8 label;
- t_image3d_lbl8 dilated;
- t_lbl8 n_labels;
-
-
- mln::io::ppm::load(input_rgb8, image.c_str());
- input_rgb5 = mln::data::transform(input_rgb8, t_rgb8_to_rgb5());
- histo = mln::data::compute(t_histo3d_fun(), input_rgb5);
- opened = mln::morpho::opening::volume(histo, mln::c6(), min_volume);
- label = mln::labeling::regional_maxima(opened, mln::c6(), n_labels);
- dilated = mln::morpho::elementary::dilation(label, mln::c26());
+ // COMPUTE THE SUM
+ t_count_array count = mln::labeling::compute(t_sum(),
+ h_histo_rgbn,
+ l_histo_lbl8,
+ n_labels);
- mln::util::array<t_sum> length((unsigned)(n_labels)+1);
+ // COMPUTE THE TOTAL
+ for (unsigned i = 0; i <= n_labels; ++i)
+ {
+ unsigned c = count[i];
+ nb += c;
+ }
+ // COMPUTE THE PERCENTAGES
for (unsigned i = 0; i <= n_labels; ++i)
- length(i).init();
+ if (0 < count[i])
+ {
+ abs[i] = ((float)count[i] / nb)*100.0;
+ rel[i] = ((float)count[i] / (nb - count[0]))*100.0;
+ }
- mln::labeling::compute(length, histo, dilated, n_labels);
+ // COMPUTE THE MEAN
+
+ t_mean_array mean = mln::labeling::compute(t_mean(),
+ i_input_rgb8,
+ l_input_lbl8,
+ n_labels);
- timer.stop();
- // STOP IMAGE PROCESSING CHAIN
+ // CORRECT 0 LABEL STATS
+ rel[0] = 0;
+ mean[0][0] = 255.0;
+ mean[0][1] = 255.0;
+ mean[0][2] = 0.0;
- std::cout << "Done in " << timer.read() << " ms"
<< std::endl;
- std::cout << "n_labels : " << n_labels << std::endl;
+ // PRINT STATS
+ std::ofstream log_stream(log.c_str());
for (unsigned i = 0; i <= n_labels; ++i)
{
- std::cout << "count[" << i << "] = " <<
length[i] << std::endl;
- }
-
- print_count(histo,label,n_labels);
+ const t_vec3f& mean_v = mean[i];
- //mln::io::plot::save_image_sh(histo, "histo.sh");
- //mln::io::plot::save_image_sh(histo, "opened.sh");
- //mln::io::plot::save_image_sh(label, "label.sh");
+ log_stream << boost::format("%2i|"
+ "r = %6.2f, g = %6.2f, b = %6.2f |"
+ "c = %7i, %%i = %5.2f, %%c = %5.2f")
+ % i
+ % mean_v[0]
+ % mean_v[1]
+ % mean_v[2]
+ % count[i]
+ % abs[i]
+ % rel[i]
+ << std::endl;
+ /*
+ std::cout << i << "|("
+ << "r = " << unquant<n>(mean_v[0]) << ",
"
+ << "g = " << unquant<n>(mean_v[1]) << ",
"
+ << "b = " << unquant<n>(mean_v[2]) <<
")|("
+ << "c = " << count[i] << ", "
+ << "%i= " << abs[i] << "%, "
+ << "%c= " << rel[i] << "%)"
+ << std::endl;
+ */
+ }
- return 0;
+ log_stream << std::endl << std::endl;
+ log_stream.flush();
+ log_stream.close();
}
void compute_stats(const mln::image2d<mln::value::rgb8>& i_input_rgb8,
@@ -546,7 +358,6 @@ void compute_stats(const mln::image2d<mln::value::rgb8>&
i_input_rgb8,
}
std::cout << std::endl << std::endl;
-
}
void save_histo(const mln::image2d<mln::value::rgb8>& input_rgb8,
@@ -565,7 +376,7 @@ void save_histo(const mln::image2d<mln::value::rgb8>&
input_rgb8,
// n < 8, n is the degree of quantification
template <unsigned n>
-void demo(const std::string& image, const unsigned min_vol)
+void demo_17_12_2009(const std::string& image, const unsigned min_vol)
{
typedef mln::value::label_8 t_lbl8;
typedef mln::value::int_u8 t_int_u8;
@@ -622,8 +433,6 @@ void demo(const std::string& image, const unsigned min_vol)
// END OF IMAGE PROCESSING CHAIN
-// i2_mean = mln::data::transform(l0_input,t_mean_lbl8_with_rgb8(mean_array));
-
// BEGIN DUMPING
save_histo(i0_input, "h0_input.pgm");
@@ -683,69 +492,235 @@ void demo(const std::string& image, const unsigned min_vol)
save_histo(i5_mean, "h5_mean.pgm");
save_histo(i5_merge, "h5_merge.pgm");
// END DUMPING
+}
-/*
- std::ostringstream name;
- std::ostringstream name2;
- std::ostringstream name3;
-
- name << "input_rgb" << n << ".ppm";
- name2 << "output_rgb" << n << ".ppm";
- name3 << "label_img" << n << ".pgm";
-
- std::cout << "Labels : " << n_labels << std::endl;
- std::cout << "Name : " << name.str() << std::endl;
-
-// mln::io::ppm::save(input_rgbn, name.str());
-
- std::cout << "timer2 : " << timer2.read() << std::endl;
- output_rgbn = mln::data::transform(input_rgbn,
- t_merge_lbl8_with_rgbn<n>(label));
- // output_rgbn = merge<n>(input_rgbn, dilated);
- mln::io::ppm::save(output_rgbn, name2.str());
-
- label_img = mln::data::transform(input_rgbn,
- t_labeling_rgbn<n>(label));
- // label_img = label_image<n>(input_rgbn, dilated);
- mln::io::pgm::save(label_img, name3.str());
-*/
-
- // localiser les couleurs sur l'image (fond en black, le reste)
-
- // La dilatation englobe beaucoup plus de couleur, mais celles-ci ne
- // sont pas forcément présentes dans l'image. Du coup, les classes ne
- // bougent pas démeusurément.
-
-// mln::io::ppm::save(input_rgb5, "input_rgb5.ppm");
-// mln::io::plot::save_image_sh(input_rgb8, "input_rgb8.sh");
-// mln::io::plot::save_image_sh(input_rgb5, "input_rgb5.sh");
-// projected = mln::display::display_histo3d_unsigned(histo);
-// mln::io::pgm::save(projected, "histo.pgm");
-// mln::io::plot::save_image_sh(histo, "histo.sh");
-// mln::io::plot::save_image_sh(opened, "opened.sh");
-// filtered = mln::display::display_histo3d_unsigned(opened);
-// mln::io::pgm::save(filtered, "filtered.pgm");
-// mln::io::plot::save_image_sh(label, "label.sh");
- // mln::io::plot::save_image_sh(dilated, "dilated.sh");
-
- /*
- // OUTPUT PHASE
- std::cout << "Output phase ..." << std::endl;
- output_rgb5 = merge(input_rgb5, dilated);
- //mln::io::ppm::save(output_rgb5, "output_rgb5.ppm");
- mln::io::plot::save_image_sh(output_rgb5, "output_rgb5.sh");
-
-
- // LABELING IMG OUTPUT
- std::cout << "Labeling img output phase ..." << std::endl;
- label_img = label_image(input_rgb5, dilated);
- mln::io::pgm::save(label_img, "label_img.pgm");
-
- // BUILDING MEAN VALUES
- std::cout << "Building mean values phase ..." << std::endl;
- mean_rgb5 = mln::labeling::mean_values(input_rgb5, label_img, n_labels);
- mln::io::ppm::save(mean_rgb5, "mean.ppm");
- */
+// n < 8, n is the degree of quantification
+template <unsigned n>
+void demo_21_12_2009(const std::string& image, const unsigned min_vol)
+{
+ typedef mln::value::label_8 t_lbl8;
+ typedef mln::value::int_u8 t_int_u8;
+ typedef mln::value::rgb8 t_rgb8;
+ typedef mln::value::rgb<n> t_rgbn;
+ typedef mln::image3d<t_lbl8> t_image3d_lbl8;
+ typedef mln::image2d<t_lbl8> t_image2d_lbl8;
+ typedef mln::image2d<t_rgb8> t_image2d_rgb8;
+ typedef mln::image2d<t_rgbn> t_image2d_rgbn;
+ typedef mln::image2d<t_int_u8> t_image2d_int_u8;
+ typedef mln::image3d<unsigned> t_histo3d;
+ typedef mln::image2d<unsigned> t_histo2d;
+ typedef mln::fun::v2v::rgb8_to_rgbn<n> t_rgb8_to_rgbn;
+ typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
+
+ // START OF IMAGE PROCESSING CHAIN
+ t_image2d_rgb8 i0_input; // input rgb8
+ t_histo3d h0_input; // histo input
+
+ t_image2d_rgbn i1_input; // input rgbn
+ t_histo3d h1_input; // histo input
+
+ t_histo3d h2_input; // histo opened
+ t_image3d_lbl8 l2_histo; // label histo
+ t_image2d_lbl8 l2_input; // label image
+ t_image2d_rgb8 i2_merge; // merge label
+ t_image2d_rgb8 i2_mean; // mean label
+
+ t_image3d_lbl8 l5_histo; // label iz 2
+ t_image2d_lbl8 l5_input; // label image
+ t_image2d_rgb8 i5_merge; // merge label
+ t_image2d_rgb8 i5_mean; // mean label
+
+ t_lbl8 n_lbl; // nb class
+
+ mln::io::ppm::load(i0_input, image.c_str());
+ i1_input = mln::data::transform(i0_input, t_rgb8_to_rgbn());
+ h1_input = mln::data::compute(t_histo3d_fun(), i1_input);
+ h2_input = mln::morpho::opening::volume(h1_input, mln::c6(), min_vol);
+ l2_histo = mln::labeling::regional_maxima(h2_input, mln::c6(), n_lbl);
+ l5_histo = mln::transform::influence_zone_geodesic(l2_histo, mln::c26(), 2);
+ // END OF IMAGE PROCESSING CHAIN
+
+ // BEGIN DUMPING
+ save_histo(i0_input, "h0_input.pgm");
+
+ // without nothing
+ l2_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l2_histo));
+ i2_mean = mln::labeling::mean_values(i0_input, l2_input, n_lbl);
+ i2_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l2_histo));
+
+ compute_stats(i0_input, l2_input, h1_input, l2_histo, n_lbl);
+
+ mln::io::pgm::save(l2_input, "l2_input.pgm");
+ mln::io::ppm::save(i2_mean, "i2_mean.ppm");
+ mln::io::ppm::save(i2_merge, "i2_merge.ppm");
+
+ save_histo(i2_mean, "h2_mean.pgm");
+ save_histo(i2_merge, "h2_merge.pgm");
+
+ // with restricted geodesic influence
+ l5_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l5_histo));
+ i5_mean = mln::labeling::mean_values(i0_input, l5_input, n_lbl);
+ i5_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l5_histo));
+
+ compute_stats(i0_input, l5_input, h1_input, l5_histo, n_lbl);
+
+ mln::io::pgm::save(l5_input, "l5_input.pgm");
+ mln::io::ppm::save(i5_mean, "i5_mean.ppm");
+ mln::io::ppm::save(i5_merge, "i5_merge.ppm");
+
+ save_histo(i5_mean, "h5_mean.pgm");
+ save_histo(i5_merge, "h5_merge.pgm");
+ // END DUMPING
+}
+
+
+// EXE THEO
+// a.out input.ppm q v output.ppm [log.txt]
+// input.ppm ==> l'image 8 bits couleur format ppm
+// q ==> la quantification [2,3,4,5,6,7,8]
+// v ==> l'effectif minimal de chaque classe [0 = pas de filtrage]
+// output.ppm ==> l'image où l'étiquette est remplacée par la couleur moyenne
+// log.txt ==> le fichier de statistiques [optionnel]
+
+// n < 8, n is the degree of quantification
+template <unsigned n>
+void exe_theo_22_12_2009(const std::string& input,
+ const unsigned min_vol,
+ const std::string& output,
+ const std::string& log)
+{
+ typedef mln::value::label_8 t_lbl8;
+ typedef mln::value::int_u8 t_int_u8;
+ typedef mln::value::rgb8 t_rgb8;
+ typedef mln::value::rgb<n> t_rgbn;
+ typedef mln::image3d<t_lbl8> t_image3d_lbl8;
+ typedef mln::image2d<t_lbl8> t_image2d_lbl8;
+ typedef mln::image2d<t_rgb8> t_image2d_rgb8;
+ typedef mln::image2d<t_rgbn> t_image2d_rgbn;
+ typedef mln::image2d<t_int_u8> t_image2d_int_u8;
+ typedef mln::image3d<unsigned> t_histo3d;
+ typedef mln::image2d<unsigned> t_histo2d;
+ typedef mln::fun::v2v::rgb8_to_rgbn<n> t_rgb8_to_rgbn;
+ typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
+
+ // START OF IMAGE PROCESSING CHAIN
+ t_image2d_rgb8 i0_input; // input rgb8
+ t_histo3d h0_input; // histo input
+
+ t_image2d_rgbn i1_input; // input rgbn
+ t_histo3d h1_input; // histo input
+
+ t_histo3d h2_input; // histo opened
+ t_image3d_lbl8 l2_histo; // label histo
+
+ t_image3d_lbl8 l4_histo; // label iz
+ t_image2d_lbl8 l4_input; // label image
+ t_image2d_rgb8 i4_merge; // merge label
+ t_image2d_rgb8 i4_mean; // mean label
+
+ t_lbl8 n_lbl; // nb class
+
+ mln::io::ppm::load(i0_input, input.c_str());
+ i1_input = mln::data::transform(i0_input, t_rgb8_to_rgbn());
+ h1_input = mln::data::compute(t_histo3d_fun(), i1_input);
+
+ if (0 < min_vol)
+ h2_input = mln::morpho::opening::volume(h1_input, mln::c6(), min_vol);
+ else
+ h2_input = h1_input; // no filtering
+
+ l2_histo = mln::labeling::regional_maxima(h2_input, mln::c6(), n_lbl);
+ l4_histo = mln::transform::influence_zone_geodesic(l2_histo, mln::c26());
+ // END OF IMAGE PROCESSING CHAIN
+
+ // BEGIN DUMPING
+ l4_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l4_histo));
+ i4_mean = mln::labeling::mean_values(i0_input, l4_input, n_lbl);
+
+ if (0 < log.size())
+ compute_stats(i0_input, l4_input, h1_input, l4_histo, n_lbl, log);
+
+ mln::io::ppm::save(i4_mean, output.c_str());
+ // END DUMPING
+}
+
+// n < 8, n is the degree of quantification
+template <unsigned n>
+void demo_22_12_2009(const std::string& image, const unsigned min_vol)
+{
+ typedef mln::value::label_8 t_lbl8;
+ typedef mln::value::int_u8 t_int_u8;
+ typedef mln::value::rgb8 t_rgb8;
+ typedef mln::value::rgb<n> t_rgbn;
+ typedef mln::image3d<t_lbl8> t_image3d_lbl8;
+ typedef mln::image2d<t_lbl8> t_image2d_lbl8;
+ typedef mln::image2d<t_rgb8> t_image2d_rgb8;
+ typedef mln::image2d<t_rgbn> t_image2d_rgbn;
+ typedef mln::image2d<t_int_u8> t_image2d_int_u8;
+ typedef mln::image3d<unsigned> t_histo3d;
+ typedef mln::image2d<unsigned> t_histo2d;
+ typedef mln::fun::v2v::rgb8_to_rgbn<n> t_rgb8_to_rgbn;
+ typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
+
+ // START OF IMAGE PROCESSING CHAIN
+ t_image2d_rgb8 i0_input; // input rgb8
+ t_histo3d h0_input; // histo input
+
+ t_image2d_rgbn i1_input; // input rgbn
+ t_histo3d h1_input; // histo input
+
+ t_histo3d h2_input; // histo opened
+ t_image3d_lbl8 l2_histo; // label histo
+ t_image2d_lbl8 l2_input; // label image
+ t_image2d_rgb8 i2_merge; // merge label
+ t_image2d_rgb8 i2_mean; // mean label
+
+ t_image3d_lbl8 l5_histo; // label iz 2
+ t_image2d_lbl8 l5_input; // label image
+ t_image2d_rgb8 i5_merge; // merge label
+ t_image2d_rgb8 i5_mean; // mean label
+
+ t_lbl8 n_lbl; // nb class
+
+ mln::io::ppm::load(i0_input, image.c_str());
+ i1_input = mln::data::transform(i0_input, t_rgb8_to_rgbn());
+ h1_input = mln::data::compute(t_histo3d_fun(), i1_input);
+ h2_input = mln::morpho::opening::volume(h1_input, mln::c6(), min_vol);
+ l2_histo = mln::labeling::regional_maxima(h2_input, mln::c6(), n_lbl);
+ l5_histo = mln::transform::influence_zone_geodesic(l2_histo, mln::c26(), 2);
+ // END OF IMAGE PROCESSING CHAIN
+
+ // BEGIN DUMPING
+ save_histo(i0_input, "h0_input.pgm");
+
+ // without nothing
+ l2_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l2_histo));
+ i2_mean = mln::labeling::mean_values(i0_input, l2_input, n_lbl);
+ i2_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l2_histo));
+
+ compute_stats(i0_input, l2_input, h1_input, l2_histo, n_lbl);
+
+ mln::io::pgm::save(l2_input, "l2_input.pgm");
+ mln::io::ppm::save(i2_mean, "i2_mean.ppm");
+ mln::io::ppm::save(i2_merge, "i2_merge.ppm");
+
+ save_histo(i2_mean, "h2_mean.pgm");
+ save_histo(i2_merge, "h2_merge.pgm");
+
+ // with restricted geodesic influence
+ l5_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l5_histo));
+ i5_mean = mln::labeling::mean_values(i0_input, l5_input, n_lbl);
+ i5_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l5_histo));
+
+ compute_stats(i0_input, l5_input, h1_input, l5_histo, n_lbl);
+
+ mln::io::pgm::save(l5_input, "l5_input.pgm");
+ mln::io::ppm::save(i5_mean, "i5_mean.ppm");
+ mln::io::ppm::save(i5_merge, "i5_merge.ppm");
+
+ save_histo(i5_mean, "h5_mean.pgm");
+ save_histo(i5_merge, "h5_merge.pgm");
+ // END DUMPING
}
@@ -774,30 +749,73 @@ void usage()
// *
}
-int main(int argc, char* args[])
+void usage_exe_theo_22_12_2009()
{
- if (argc != 3)
+ std::cout << std::endl;
+ std::cout << "a.out input.ppm q v [log.txt]"
<< std::endl;
+ std::cout << "where"
<< std::endl;
+ std::cout << "input.ppm is the 8 bits color ppm image"
<< std::endl;
+ std::cout << "q is the degree of quanification {2,3,4,5,6,7,8}"
<< std::endl;
+ std::cout << "v is the minimal size for the histogram classes"
<< std::endl;
+ std::cout << "log.txt is the statistical file for classes"
<< std::endl;
+ std::cout << std::endl;
+}
+
+int main_21_12_2009(int argc, char* args[])
+{
+ if (argc == 2)
{
// const std::string& image = OLENA_IMG_PATH"/fly.ppm";
const std::string& image = SCRIBO_PPM_IMG_PATH"/mp00082c_50p.ppm";
// const std::string& image = OLENA_IMG_PATH"/tiny.ppm";
// const std::string image = OLENA_IMG_PATH"/tiny.ppm";
- const unsigned min_volume = 1000;
- // const unsigned min_volume = atoi(args[2]);
+ // const unsigned min_volume = 1000;
+ const unsigned min_volume = atoi(args[1]);
- switch(args[2][0])
+// switch(args[1][0])
+ switch(5)
{
- case '2': demo<2>(image, min_volume); break;
- case '3': demo<3>(image, min_volume); break;
- case '4': demo<4>(image, min_volume); break;
- case '5': demo<5>(image, min_volume); break;
- case '6': demo<6>(image, min_volume); break;
- case '7': demo<7>(image, min_volume); break;
- case '8': demo<8>(image, min_volume); break;
- default: demo<5>(image, min_volume); break;
+ case '2': demo_21_12_2009<2>(image, min_volume); break;
+ case '3': demo_21_12_2009<3>(image, min_volume); break;
+ case '4': demo_21_12_2009<4>(image, min_volume); break;
+ case '5': demo_21_12_2009<5>(image, min_volume); break;
+ case '6': demo_21_12_2009<6>(image, min_volume); break;
+ case '7': demo_21_12_2009<7>(image, min_volume); break;
+ case '8': demo_21_12_2009<8>(image, min_volume); break;
+ default: demo_21_12_2009<5>(image, min_volume); break;
// default: usage(); break;
}
}
else
usage();
+
+ return 0;
+}
+
+int main(int argc, char* args[])
+{
+ if (5 == argc || 6 == argc)
+ {
+ const std::string input(args[1]);
+ const char q = args[2][0];
+ const unsigned v = atoi(args[3]);
+ const std::string output(args[4]);
+ const std::string log(6 == argc? args[5] : "");
+
+ switch(q)
+ {
+ case '2': exe_theo_22_12_2009<2>(input, v, output, log); break;
+ case '3': exe_theo_22_12_2009<3>(input, v, output, log); break;
+ case '4': exe_theo_22_12_2009<4>(input, v, output, log); break;
+ case '5': exe_theo_22_12_2009<5>(input, v, output, log); break;
+ case '6': exe_theo_22_12_2009<6>(input, v, output, log); break;
+ case '7': exe_theo_22_12_2009<7>(input, v, output, log); break;
+ case '8': exe_theo_22_12_2009<8>(input, v, output, log); break;
+ default: usage_exe_theo_22_12_2009(); break;
+ }
+ }
+ else
+ usage_exe_theo_22_12_2009();
+
+ return 0;
}
--
1.5.6.5