milena r3577: Clean binarisation processing chain using sharpness

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-03-25 Edwin Carlinet <carlinet@lrde.epita.fr> Clean binarisation processing chain using sharpness. * sandbox/edwin/tree/run.hh: Add trace entering/exiting functions. * sandbox/edwin/tree/sharp.cc: Clean file. --- Makefile | 3 + configure | 4 ++ run.hh | 16 ++++++++- sharp.cc | 108 +++++++++++++++++++++++++++++++++++++++----------------------- 4 files changed, 88 insertions(+), 43 deletions(-) Index: trunk/milena/sandbox/edwin/tree/configure =================================================================== --- trunk/milena/sandbox/edwin/tree/configure (revision 3576) +++ trunk/milena/sandbox/edwin/tree/configure (revision 3577) @@ -5,6 +5,10 @@ if [ "$arg" == "--debug" ]; then debug=1; fi + + if [ "$arg" == "--release" ]; then + release=1; + fi done rm -f makefile.rules @@ -12,3 +16,6 @@ if [ "$debug" ]; then echo 'DEBUG=1' > makefile.rules fi \ No newline at end of file +if [ "$release" ]; then + echo 'RELEASE=1' > makefile.rules +fi \ No newline at end of file Index: trunk/milena/sandbox/edwin/tree/sharp.cc =================================================================== --- trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3576) +++ trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3577) @@ -24,7 +24,7 @@ /* io */ #include <mln/io/pgm/load.hh> #include <mln/io/pgm/save.hh> -#include <mln/io/ppm/save.hh> +#include <mln/io/pbm/save.hh> #include <../../theo/color/change_attributes.hh> /* data & pw */ @@ -34,11 +34,8 @@ #include <mln/data/paste.hh> #include <mln/pw/all.hh> -/* labeling */ -#include <mln/value/label.hh> -#include <mln/labeling/blobs.hh> -#include <mln/debug/colorize.hh> - +/* trace */ +#include <mln/trace/quiet.hh> /* std */ #include <string> @@ -49,11 +46,11 @@ void usage(char** argv) { - std::cerr << "usage: " << argv[0] << " input [--debug]" << std::endl; + std::cerr << "usage: " << argv[0] << " input [--debug] [-n nbr_components | -s sharpness] [-c card]" << std::endl; abort(); } -void dsp(const char* str) +void dsp(const std::string& str) { std::cout << std::endl << "*********************" << std::endl @@ -67,11 +64,30 @@ { using namespace mln; using value::int_u8; + std::string arg; + unsigned nb_components = 0; + unsigned card = 0; + double sharpness = 0; if (argc < 2) usage(argv); - mydebug = (argc >= 3 && std::string(argv[2]) == "--debug"); + for (int i = 2; i < argc; i++) + { + arg = std::string(argv[i]); + if (arg == "--debug") + mydebug = true; + else if (arg == "-n" && i != argc) + nb_components = atoi(argv[++i]); + else if (arg == "-s" && i != argc) + sharpness = atof(argv[++i]); + else if (arg == "-c" && i != argc) + card = atoi(argv[++i]); + else if (arg == "--trace") + trace::quiet = false; + else + usage (argv); + } /* Image loadin' */ @@ -91,13 +107,12 @@ typedef morpho::attribute::sharpness<I> sharp_t; typedef mln_ch_value_(I, double) A; + if (mydebug) + dsp("Image sharp attribute"); + A a = morpho::tree::compute_attribute_image(sharp_t (), tree); morpho::tree::propagate_representant(tree, a); - if (mydebug) { - dsp("Image sharp attribute"); display_tree_attributes(tree, a); - } - /* We don't want little components */ // So we compute card attribute and we filter big components @@ -106,30 +121,41 @@ // optional extra argument to compute_attribute where the // accumulators image will be stored. + if (card) + { typedef morpho::attribute::card<I> card_t; typedef mln_ch_value_(tree_t::function, mln_result_(card_t)) B; + if (mydebug) + dsp("Image card attribute"); + B b = morpho::tree::compute_attribute_image(card_t (), tree); morpho::tree::propagate_representant(tree, b); - if (mydebug) { - dsp("Image card attribute"); display_tree_attributes(tree, b); + a = duplicate((fun::p2v::ternary(pw::value(b) > pw::cst(card), pw::value(a), pw::cst(0.0))) | a.domain()); } - a = duplicate((fun::p2v::ternary(pw::value(b) > pw::cst(100), pw::value(a), pw::cst(0.0))) | a.domain()); - - /* Run max accumulator */ accumulator::arg_max<A> argmax(a); p_array< mln_psite_(A) > obj_array; // Array of object components. - mln_VAR(predicate, pw::value(a) > pw::cst(0.7)); - obj_array = morpho::tree::run_while(tree, a, argmax, predicate); - if (mydebug) { - dsp("Run max accumulator, lk 4 5 objs"); display_tree_attributes(tree, a); + std::stringstream s("Run max accumulator, look for "); + if (nb_components) + s << nb_components << " components."; + else + s << "components whose treshold > " << sharpness; + dsp(s.str()); } + if (!nb_components) { + mln_VAR(predicate, pw::value(a) > pw::cst(sharpness)); + obj_array = morpho::tree::run_while(tree, a, argmax, predicate); + } else { + obj_array = morpho::tree::run_ntimes(tree, a, argmax, nb_components); + } + + /* Print them */ if (mydebug) { dsp("Image Filtered Components"); @@ -139,6 +165,10 @@ } /* Now Back Propagate to component */ + + if (mydebug) { + dsp("Create mask and propagate"); + } typedef mln_ch_value_(I, bool) M; M mask; initialize(mask, a); @@ -151,28 +181,26 @@ propagate_node_to_descendants(c, tree, mask); } morpho::tree::propagate_representant(tree, mask); + io::pbm::save(mask, "binary.pbm"); // mask now contains all nodes related to objects - if (mydebug) { - dsp("Create mask and propagate"); display_tree_attributes(tree, mask); - } - /* Labeling */ - typedef mln_ch_value_(I, value::label<8>) L; - value::label<8> nlabel; - L label = labeling::blobs(mask, c4(), nlabel); - io::ppm::save(debug::colorize(value::rgb8(), label, nlabel), "label.pgm"); - - /* Now store output image image */ - I out; - initialize(out, input); - data::fill(out, 0); - data::paste(input | pw::value(mask), out); + /* EXTRA */ + + // /* Labeling */ +// typedef mln_ch_value_(I, value::label<8>) L; +// value::label<8> nlabel; +// L label = labeling::blobs(mask, c4(), nlabel); +// io::ppm::save(debug::colorize(value::rgb8(), label, nlabel), "label.pgm"); + + +// /* Now store output image */ +// I out; +// initialize(out, input); +// data::fill(out, 0); +// data::paste(input | pw::value(mask), out); +// io::pgm::save(out, "output.pgm"); - if (mydebug) { - dsp("Mask input"); display_tree_attributes(tree, out); - } - io::pgm::save(out, "output.pgm"); } Index: trunk/milena/sandbox/edwin/tree/run.hh =================================================================== --- trunk/milena/sandbox/edwin/tree/run.hh (revision 3576) +++ trunk/milena/sandbox/edwin/tree/run.hh (revision 3577) @@ -36,6 +36,9 @@ # include <mln/core/site_set/p_array.hh> # include <mln/util/pix.hh> +# include <mln/trace/entering.hh> +# include <mln/trace/exiting.hh> + # include "propagate_node.hh" namespace mln { @@ -167,12 +170,15 @@ Accumulator<ACC>& acc, Function_p2b<P2B>& pred) { + trace::entering("mln::morpho::tree::run_while"); A& a = exact(a_); mln_precondition(tree.f().domain() == a.domain()); mln_precondition(a.is_valid()); - return internal::run_while(tree, a, exact(acc), exact(pred)); + p_array< mln_psite(A) > arr = internal::run_while(tree, a, exact(acc), exact(pred)); + trace::exiting("mln::morpho::tree::run_while"); + return arr; } template <typename T, typename A, typename ACC> @@ -183,8 +189,11 @@ Accumulator<ACC>& acc, unsigned n) { + trace::entering("mln::morpho::tree::run_ntimes"); internal::ncard predicate(n - 1); - return run_while(tree, a, acc, predicate); + p_array< mln_psite(A) > arr = run_while(tree, a, acc, predicate); + trace::exiting("mln::morpho::tree::run_ntimes"); + return arr; } template <typename T, typename A, typename I> @@ -193,15 +202,18 @@ const Image<I>& a_, Accumulator<A>& accu_) { + trace::entering("mln::morpho::tree::run"); A& accu = exact(accu_); const I& a = exact(a_); + mln_precondition(tree.f().domain() == a.domain()); mln_precondition(a.is_valid()); mln_up_node_piter(T) n(tree); for_all(n) accu.take(make::pix(a, n)); + trace::exiting("mln::morpho::tree::run"); return (accu.to_result()); } Index: trunk/milena/sandbox/edwin/tree/Makefile =================================================================== --- trunk/milena/sandbox/edwin/tree/Makefile (revision 3576) +++ trunk/milena/sandbox/edwin/tree/Makefile (revision 3577) @@ -9,7 +9,8 @@ CXXFLAGS=-I$(MILENADIR) -I./ -W -Wall -CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG -O1) +CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\ + $(if $(RELEASE), -O3, -O1)) CXX=g++ LD=g++
participants (1)
-
Edwin Carlinet