* green/demo/labeling/regional_maxima/regional_maxima.cc: Add
many modifications to reach the current software state. There is some
nomenclatura, some refactoring and debugging.
---
milena/sandbox/ChangeLog | 8 +
.../labeling/regional_maxima/regional_maxima.cc | 354 ++++++++++++--------
2 files changed, 214 insertions(+), 148 deletions(-)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index f850e69..3a7ffb7 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-18 Yann Jacquelet<jacquelet(a)lrde.epita.fr>
+
+ Fix the right behaviour of the regmax software.
+
+ * green/demo/labeling/regional_maxima/regional_maxima.cc: Add
+ many modifications to reach the current software state. There is some
+ nomenclatura, some refactoring and debugging.
+
2009-12-17 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Fix bug in the direction of projection.
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 c832486..65b6608 100644
--- a/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
+++ b/milena/sandbox/green/demo/labeling/regional_maxima/regional_maxima.cc
@@ -27,7 +27,8 @@
// #include <mln/data/stretch.hh>
#include <mln/data/transform.hh>
-// #include <mln/display/display_histo.hh>
+// #include <mln/debug/println.hh>
+#include <mln/display/display_histo.hh>
#include <mln/fun/v2v/rgb8_to_rgbn.hh>
@@ -49,6 +50,7 @@
#include <mln/opt/at.hh>
+#include <mln/transform/influence_zone_geodesic.hh>
// #include <mln/pw/value.hh>
#include <mln/util/array.hh>
@@ -255,108 +257,6 @@ void print_count2(const mln::image2d<mln::value::rgb<n>
>& input_rgbn,
}
}
-template <unsigned n>
-mln::image2d<mln::value::label_8>
-compute_stats(const mln::image2d<mln::value::rgb8>& input_rgb8,
- 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::rgb8 t_rgb8;
- 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::image2d<t_lbl8> t_image2d_lbl8;
- typedef mln::image2d<t_rgbn> t_image2d_rgbn;
- typedef mln::image2d<t_rgb8> t_image2d_rgb8;
- typedef mln::image2d<t_int_un> t_image2d_int_un;
- typedef mln::util::array<unsigned> t_count_array;
- typedef mln::util::array<t_vec3f> t_mean_array;
-
- 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)
- {
- abs[i] = 0.0;
- rel[i] = 0.0;
- }
-
- // COMPUTE THE SUM
- t_count_array count = mln::labeling::compute(t_sum(),
- histo,
- label,
- n_labels);
-
- // 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)
- if (0 < count[i])
- {
- abs[i] = ((float)count[i] / nb)*100.0;
- rel[i] = ((float)count[i] / (nb - count[0]))*100.0;
- }
-
- // COMPUTE THE MEAN
- t_image2d_lbl8 label_img = mln::data::transform(input_rgbn,
- t_labeling_rgbn<n>(label));
-
- t_mean_array mean = mln::labeling::compute(t_mean(),
- input_rgb8,
- label_img,
- n_labels);
-
- // CORRECT LABEL 0 STATS
- rel[0] = 0;
- mean[0][0] = 255.0;
- mean[0][1] = 255.0;
- mean[0][2] = 0.0;
-
- for (unsigned i = 0; i <= n_labels; ++i)
- {
- const t_vec3f& mean_v = mean[i];
-
- std::cout << 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;
- */
- }
-
- t_image2d_rgb8 mean_rgb8 = mln::data::transform(label_img,
- t_mean_lbl8_with_rgb8(mean));
-
- mln::io::ppm::save(mean_rgb8, "mean.ppm");
-
- return label_img;
-}
void print_count(const mln::image3d<unsigned>& histo,
const mln::image3d<mln::value::label_8>& label,
@@ -561,9 +461,111 @@ int main2()
return 0;
}
+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)
+{
+ 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::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)
+ {
+ abs[i] = 0.0;
+ rel[i] = 0.0;
+ }
+
+ // COMPUTE THE SUM
+ t_count_array count = mln::labeling::compute(t_sum(),
+ h_histo_rgbn,
+ l_histo_lbl8,
+ n_labels);
+
+ // 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)
+ if (0 < count[i])
+ {
+ abs[i] = ((float)count[i] / nb)*100.0;
+ rel[i] = ((float)count[i] / (nb - count[0]))*100.0;
+ }
+
+ // COMPUTE THE MEAN
+
+ t_mean_array mean = mln::labeling::compute(t_mean(),
+ i_input_rgb8,
+ l_input_lbl8,
+ n_labels);
+
+ // CORRECT 0 LABEL STATS
+ rel[0] = 0;
+ mean[0][0] = 255.0;
+ mean[0][1] = 255.0;
+ mean[0][2] = 0.0;
+
+ // PRINT STATS
+ for (unsigned i = 0; i <= n_labels; ++i)
+ {
+ const t_vec3f& mean_v = mean[i];
+
+ std::cout << 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;
+ */
+ }
+
+ std::cout << std::endl << std::endl;
+
+}
+
+void save_histo(const mln::image2d<mln::value::rgb8>& input_rgb8,
+ const std::string& name)
+{
+ typedef mln::value::int_u8 t_int_u8;
+ typedef mln::image2d<t_int_u8> t_image2d_int_u8;
+ typedef mln::image3d<unsigned> t_histo3d;
+ typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
+
+ t_histo3d histo = mln::data::compute(t_histo3d_fun(), input_rgb8);
+ t_image2d_int_u8 display = mln::display::display_histo3d_unsigned(histo);
+ mln::io::pgm::save(display, name);
+}
+
+
// n < 8, n is the degree of quantification
template <unsigned n>
-void demo(const std::string& image, const unsigned min_volume)
+void demo(const std::string& image, const unsigned min_vol)
{
typedef mln::value::label_8 t_lbl8;
typedef mln::value::int_u8 t_int_u8;
@@ -580,45 +582,106 @@ void demo(const std::string& image, const unsigned min_volume)
typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
// START OF IMAGE PROCESSING CHAIN
- t_image2d_rgb8 input_rgb8;
- t_image2d_rgbn input_rgbn;
- t_image2d_rgb8 output_rgb8;
- t_image2d_rgb8 mean_rgb8;
- t_histo3d histo;
- t_histo3d histo2;
- // t_image2d_int_u8 projected;
- // t_image2d_int_u8 filtered;
- t_histo3d opened;
- t_image3d_lbl8 label;
- t_image2d_lbl8 label_img;
- t_image3d_lbl8 dilated;
- t_lbl8 n_labels;
-
- mln::io::ppm::load(input_rgb8, image.c_str());
- input_rgbn = mln::data::transform(input_rgb8, t_rgb8_to_rgbn());
- histo = mln::data::compute(t_histo3d_fun(), input_rgbn);
- 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());
+ 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 l3_histo; // label dilated
+ t_image2d_lbl8 l3_input; // label image
+ t_image2d_rgb8 i3_merge; // merge label
+ t_image2d_rgb8 i3_mean; // mean label
+
+ 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_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);
+ l3_histo = mln::morpho::elementary::dilation(l2_histo, mln::c26());
+ l4_histo = mln::transform::influence_zone_geodesic(l2_histo, mln::c26());
+ l5_histo = mln::transform::influence_zone_geodesic(l2_histo, mln::c26(), 2);
// END OF IMAGE PROCESSING CHAIN
+// i2_mean = mln::data::transform(l0_input,t_mean_lbl8_with_rgb8(mean_array));
// BEGIN DUMPING
- label_img = compute_stats(input_rgb8, input_rgbn, histo, label, n_labels);
- // mean_rgb8 = mln::labeling::mean_values(input_rgb8, label_img, n_labels);
- // mln::io::ppm::save(mean_rgb8, "mean.ppm");
+ save_histo(i0_input, "h0_input.pgm");
+
+ // without anything
+ 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");
- output_rgb8 = mln::data::transform(input_rgb8,
- t_merge_lbl8_with_rgbn<5>(label));
+ // with dilation
+ l3_input = mln::data::transform(i1_input, t_labeling_rgbn<n>(l3_histo));
+ i3_mean = mln::labeling::mean_values(i0_input, l3_input, n_lbl);
+ i3_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l3_histo));
+ compute_stats(i0_input, l3_input, h1_input, l3_histo, n_lbl);
- mln::io::ppm::save(output_rgb8, "merge.ppm");
- mln::io::pgm::save(label_img, "label.pgm");
+ mln::io::pgm::save(l3_input, "l3_input.pgm");
+ mln::io::ppm::save(i3_mean, "i3_mean.ppm");
+ mln::io::ppm::save(i3_merge, "i3_merge.ppm");
+ save_histo(i3_mean, "h3_mean.pgm");
+ save_histo(i3_merge, "h3_merge.pgm");
-// histo2 = mln::data::compute(t_histo3d_fun(), mean_rgbn);
-// mln::debug::println(histo2);
+ // with geodesic influence
+ 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);
+ i4_merge = mln::data::transform(i0_input,t_merge_lbl8_with_rgbn<n>(l4_histo));
+
+ compute_stats(i0_input, l4_input, h1_input, l4_histo, n_lbl);
+
+ mln::io::pgm::save(l4_input, "l4_input.pgm");
+ mln::io::ppm::save(i4_mean, "i4_mean.ppm");
+ mln::io::ppm::save(i4_merge, "i4_merge.ppm");
+
+ save_histo(i4_mean, "h4_mean.pgm");
+ save_histo(i4_merge, "h4_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
/*
@@ -685,25 +748,14 @@ void demo(const std::string& image, const unsigned min_volume)
*/
}
-/*
-int main_old()
-{
- demo<2>(); // 2.26 s
- demo<3>(); // 2.29 s
- demo<4>(); // 2.29 s
- demo<5>(); // 2.37 s
- demo<6>(); // 3.19 s
- demo<7>(); // 11.43 s
- demo<8>(); // 96.19 s
-}
-*/
+
void usage()
{
std::cout << std::endl;
std::cout << "regional_maxima" << std::endl;
std::cout << "image <name>" << std::endl;
std::cout << "quantification {5,6}" << std::endl;
- std::cout << "volume 1000" << std::endl;
+ std::cout << "min_volume 1000" << std::endl;
// 3 paramètres en entré:
// * l'image
@@ -712,8 +764,14 @@ void usage()
// sorties:
// * fichier de stats [etiquette|couleur moyenne|% image|% classé]
- // * couleur moyenne de l'étiquette + couleur specifique pour étiquette 0
- // * histo sur l'image d'étiquette
+ // * image de labels
+ // * image reconstruite avec la moyenne de chaque classe [i_mean]
+ // * image reconstruite avec les couleurs de chaque classe [i_merge]
+ // * histogramme original de l'image d'entrée [h_input]
+ // * histogramme projeté de mean [h_mean]
+ // * histogramme projeté de merge [h_merge]
+
+ // *
}
int main(int argc, char* args[])
--
1.5.6.5