last-svn-commit-229-g58e82cd Add some futur materials on regional maxima.

* test_labelling_2.cc: New file. * test_labelling_3.cc: New file. --- scribo/sandbox/green/ChangeLog | 7 + .../sandbox/green/test_labelling_2.cc | 318 +++++++------------- .../sandbox/green/test_labelling_3.cc | 25 ++- 3 files changed, 141 insertions(+), 209 deletions(-) copy milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc => scribo/sandbox/green/test_labelling_2.cc (64%) copy milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc => scribo/sandbox/green/test_labelling_3.cc (92%) diff --git a/scribo/sandbox/green/ChangeLog b/scribo/sandbox/green/ChangeLog index 7106b22..81749fe 100644 --- a/scribo/sandbox/green/ChangeLog +++ b/scribo/sandbox/green/ChangeLog @@ -1,3 +1,10 @@ +2010-06-30 Yann Jacquelet <jacquelet@lrde.epita.fr> + + Add some futur materials on regional maxima. + + * test_labelling_2.cc: New file. + * test_labelling_3.cc: New file. + 2010-06-28 Yann Jacquelet <jacquelet@lrde.epita.fr> Implement the kmean algorithh and start to optimize it. diff --git a/milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc b/scribo/sandbox/green/test_labelling_2.cc similarity index 64% copy from milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc copy to scribo/sandbox/green/test_labelling_2.cc index 30e68b1..28129f1 100644 --- a/milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc +++ b/scribo/sandbox/green/test_labelling_2.cc @@ -1,4 +1,29 @@ -// DEMO ON KMEAN2D +// Copyright (C) 2007,2008,2009,2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +/// \file #include <mln/clustering/kmean2d.hh> @@ -53,10 +78,10 @@ // Ok pour la convergence. // demander à Théo pour le temps (45 sec pour chaque launching [house,3 cl.]) // -void do_demo_kmean(const std::string& image, - const unsigned k_center, - const unsigned n_times, - const unsigned watch_dog) +void do_demo(const std::string& image, + const unsigned k_center, + const unsigned n_times, + const unsigned watch_dog) { typedef mln::clustering::kmean2d<double,8> t_kmean; typedef mln::value::rg<8> t_rg8; @@ -104,6 +129,21 @@ void do_demo_kmean(const std::string& image, } +void demo(const std::string& image = OLENA_IMG_PATH"/house.ppm", + const unsigned k_center = 3, + const unsigned n_times = 10, + const unsigned watch_dog = 10) +{ + std::cout << "----------------------------------------" << std::endl; + std::cout << "Launching the demo with these parameters" << std::endl; + std::cout << "image : " << image << std::endl; + std::cout << "k_center : " << k_center << std::endl; + std::cout << "n_times : " << n_times << std::endl; + std::cout << "watch_dog : " << watch_dog << std::endl; + std::cout << "----------------------------------------" << std::endl; + + do_demo(image, k_center, n_times, watch_dog); +} mln::image2d<mln::value::rgb<8> > merge(const mln::image2d<mln::value::rg<8> >& input, @@ -134,124 +174,91 @@ merge(const mln::image2d<mln::value::rg<8> >& input, } -// -// Watershed image processing chain. -// -void do_demo_watershed(const std::string& image, - const unsigned k_center, - const unsigned n_times, - const unsigned watch_dog) -{ - typedef mln::value::label_8 t_lbl8; - typedef mln::value::rg<8> t_rg8; - typedef mln::value::rgb8 t_rgb8; - typedef mln::value::int_u8 t_int_u8; - typedef mln::image2d<t_lbl8> t_image2d_lbl8; - typedef mln::image2d<t_rgb8> t_image2d_rgb8; - typedef mln::image2d<t_int_u8> t_image2d_int_u8; - typedef mln::image2d<t_rg8> t_image2d_rg8; - typedef mln::image2d<unsigned> t_histo2d; - typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; - typedef mln::fun::v2v::rg_to_rgb<8> t_rg_to_rgb; - - t_image2d_rgb8 img_rgb8; - t_image2d_rgb8 output; - t_image2d_rgb8 img_cast; - t_image2d_rg8 img_rg8; - t_histo2d histo; - t_image2d_lbl8 label; - t_lbl8 n_labels; - t_histo2d reverted; - - // IMAGE LOADING PHASE - mln::io::ppm::load(house_rgb8, image.c_str()); - img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); - img_cast = mln::data::transform(img_rg8, t_rg_to_rgb()); - mln::io::ppm::save(img_cast, "red_green.ppm"); - - // HISTO COMPUTING AND FILTERING PHASE - histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); - mln::io::plot::save_image_sh(histo, "histo.sh"); - - //histo = mln::morpho::elementary::opening(histo, mln::c4()); - - mln::io::plot::save_image_sh(histo, "histo.sh"); - - // LABELING PHASE - reverted = mln::arith::revert(histo); - label = mln::morpho::watershed::flooding(reverted, mln::c4(), n_labels); - mln::io::pgm::save(label, "label.pgm"); +void usage(const int argc, const char *args[]) +{ + std::cout << "----------------------------------------" << std::endl; + std::cout << "argc : " << argc << std::endl; - // OUTPUT PHASE - output = merge(house_rg8, label); + for (int i = 0; i < argc; ++i) + std::cout << "args[" << i << "] : " << args[i] << std::endl; - mln::io::ppm::save(output, "merge.ppm"); + std::cout << "----------------------------------------" << std::endl; + std::cout << "usage: kmean2d [image [k_center [n_times [watch_dog]]]]" + << std::endl; + std::cout << "pbm image (points to work with)" << std::endl; + std::cout << "unsigned k_center (number of centers)" << std::endl; + std::cout << "unsigned n_times (number of launching)" << std::endl; + std::cout << "unsigned watch_dog (convergence loop)" << std::endl; + std::cout << "----------------------------------------" << std::endl; } - -// -// Regional maxima image processing chain. -// -void do_demo_regional1(const std::string& image, - const unsigned k_center, - const unsigned n_times, - const unsigned watch_dog) +bool char_to_unsigned(const bool status, const char *arg, unsigned& val) { - typedef mln::value::label_8 t_lbl8; - typedef mln::value::rg<8> t_rg8; - typedef mln::value::rgb8 t_rgb8; - typedef mln::value::int_u8 t_int_u8; - typedef mln::image2d<t_lbl8> t_image2d_lbl8; - typedef mln::image2d<t_rgb8> t_image2d_rgb8; - typedef mln::image2d<t_int_u8> t_image2d_int_u8; - typedef mln::image2d<t_rg8> t_image2d_rg8; - typedef mln::image2d<unsigned> t_histo2d; - typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; - typedef mln::fun::v2v::rg_to_rgb<8> t_rg_to_rgb; + bool result = false; - t_image2d_rgb8 img_rgb8; - t_image2d_rgb8 output; - t_image2d_rgb8 img_cast; - t_image2d_rg8 img_rg8; - t_histo2d histo; - t_histo2d opened; - t_image2d_lbl8 label; - t_image2d_lbl8 dilated; - t_lbl8 n_labels; + if (status) + { + std::istringstream arg_stream(arg); + arg_stream >> val; - // IMAGE LOADING PHASE - mln::io::ppm::load(img_rgb8, image.c_str()); - img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); - img_cast = mln::data::transform(img_rg8, t_rg_to_rgb()); - mln::io::ppm::save(img_cast, "red_green.ppm"); + result = !arg_stream.fail(); + } + return result; +} - // HISTO COMPUTING PHASE - histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); - mln::io::plot::save_image_sh(histo, "histo.sh"); +bool char_to_string(const bool status, const char *arg, std::string& val) +{ + bool result = false; + if (status) + { + std::istringstream arg_stream(arg); - // HISTO FILTERING PHASE - opened = mln::morpho::elementary::opening(histo, mln::c8()); - mln::io::plot::save_image_sh(opened, "opened.sh"); + arg_stream >> val; + return !arg_stream.fail(); + } - // HISTO LABELING PHASE - label = mln::labeling::regional_maxima(opened, mln::c8(), n_labels); - mln::io::pgm::save(label, "label.pgm"); + return result; +} +int main(const int argc, const char *args[]) +{ + std::string image("top"); + unsigned k_center; + unsigned watch_dog; + unsigned n_times; + bool status = true; - // HISTO FUZZY PHASE - dilated = mln::morpho::elementary::dilation(label, mln::c8()); - mln::io::pgm::save(dilated, "dilated.pgm"); + switch (argc) + { + case 5: status = char_to_unsigned(status, args[4], watch_dog); + case 4: status = char_to_unsigned(status, args[3], n_times); + case 3: status = char_to_unsigned(status, args[2], k_center); + case 2: status = char_to_string(status, args[1], image); break; + case 1: status = true; break; + default: status = false; + } + if (status) + { + switch (argc) + { + case 1: demo(); break; + case 2: demo(image); break; + case 3: demo(image, k_center); break; + case 4: demo(image, k_center, n_times); break; + case 5: demo(image, k_center, n_times, watch_dog); break; + } + } + else + usage(argc, args); - // OUTPUT PHASE - output = merge(img_rg8, dilated); - mln::io::ppm::save(output, "merge.ppm"); + return 0; } // @@ -333,108 +340,3 @@ void do_demo_regional2(const std::string& image, -void demo(const std::string& image = SCRIBO_PPM_IMG_PATH"/mp00082c_50p.ppm", - //const std::string& image = OLENA_IMG_PATH"/house.ppm", - const unsigned k_center = 2, - //const unsigned k_center = 3, - const unsigned n_times = 10, - const unsigned watch_dog = 10) -{ - std::cout << "----------------------------------------" << std::endl; - std::cout << "Launching the demo with these parameters" << std::endl; - std::cout << "image : " << image << std::endl; - std::cout << "k_center : " << k_center << std::endl; - std::cout << "n_times : " << n_times << std::endl; - std::cout << "watch_dog : " << watch_dog << std::endl; - std::cout << "----------------------------------------" << std::endl; - -// do_demo_kmean(image, k_center, n_times, watch_dog); -// do_demo_watershed(image, k_center, n_times, watch_dog); - do_demo_regional1(image, k_center, n_times, watch_dog); - //do_demo_regional2(image, k_center, n_times, watch_dog); -} - -void usage(const int argc, const char *args[]) -{ - std::cout << "----------------------------------------" << std::endl; - std::cout << "argc : " << argc << std::endl; - - for (int i = 0; i < argc; ++i) - std::cout << "args[" << i << "] : " << args[i] << std::endl; - - std::cout << "----------------------------------------" << std::endl; - std::cout << "usage: kmean2d [image [k_center [n_times [watch_dog]]]]" - << std::endl; - std::cout << "pbm image (points to work with)" << std::endl; - std::cout << "unsigned k_center (number of centers)" << std::endl; - std::cout << "unsigned n_times (number of launching)" << std::endl; - std::cout << "unsigned watch_dog (convergence loop)" << std::endl; - std::cout << "----------------------------------------" << std::endl; -} - -bool char_to_unsigned(const bool status, const char *arg, unsigned& val) -{ - bool result = false; - - if (status) - { - std::istringstream arg_stream(arg); - - arg_stream >> val; - - result = !arg_stream.fail(); - } - - return result; -} - -bool char_to_string(const bool status, const char *arg, std::string& val) -{ - bool result = false; - - if (status) - { - std::istringstream arg_stream(arg); - - arg_stream >> val; - - return !arg_stream.fail(); - } - - return result; -} - -int main(const int argc, const char *args[]) -{ - std::string image("top"); - unsigned k_center; - unsigned watch_dog; - unsigned n_times; - bool status = true; - - switch (argc) - { - case 5: status = char_to_unsigned(status, args[4], watch_dog); - case 4: status = char_to_unsigned(status, args[3], n_times); - case 3: status = char_to_unsigned(status, args[2], k_center); - case 2: status = char_to_string(status, args[1], image); break; - case 1: status = true; break; - default: status = false; - } - - if (status) - { - switch (argc) - { - case 1: demo(); break; - case 2: demo(image); break; - case 3: demo(image, k_center); break; - case 4: demo(image, k_center, n_times); break; - case 5: demo(image, k_center, n_times, watch_dog); break; - } - } - else - usage(argc, args); - - return 0; -} diff --git a/milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc b/scribo/sandbox/green/test_labelling_3.cc similarity index 92% copy from milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc copy to scribo/sandbox/green/test_labelling_3.cc index 30e68b1..317832b 100644 --- a/milena/sandbox/green/demo/clustering/kmean2d/kmean2d.cc +++ b/scribo/sandbox/green/test_labelling_3.cc @@ -1,4 +1,27 @@ -// DEMO ON KMEAN2D +// Copyright (C) 2007,2008,2009,2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. #include <mln/clustering/kmean2d.hh> -- 1.5.6.5
participants (1)
-
Yann Jacquelet