
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-03-01 Edwin Carlinet <carlinet@lrde.epita.fr> [EXO2] Add shell script for exo2. * sandbox/theo/rush/exo2/Makefile * sandbox/theo/rush/exo2/exo2.cc * sandbox/theo/rush/exo2/exo2.sh: Shell script for exo2. --- Makefile | 4 ++++ exo2.cc | 35 ++++++++++++++++++++++++++--------- exo2.sh | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) Index: trunk/milena/sandbox/theo/rush/exo2/exo2.cc =================================================================== --- trunk/milena/sandbox/theo/rush/exo2/exo2.cc (revision 3449) +++ trunk/milena/sandbox/theo/rush/exo2/exo2.cc (revision 3450) @@ -18,28 +18,36 @@ #include <mln/morpho/attribute/card.hh> #include <mln/morpho/attribute/sharpness.hh> +#include <string> + #include "propagate.hh" namespace mln { + /// Structure to simplify filtering using min tree. template <typename I> struct treefilter { typedef p_array< mln_site(I) > S; typedef morpho::tree::data<I,S> tree_t; + /// Constructor: Make the min tree based on the image \p f_, then + /// performs calculus using \p a_ attribute. To finish, it filters + /// tree's nodes which values are in [lambda1, lambda2] set. template <typename A> treefilter(Image<I>& f_, Accumulator<A> a_, double lambda1 = mln_min(double), double lambda2 = mln_max(double)); + /// Get the min tree performed. tree_t& tree() { return tree_; }; + + /// Get the boolean image got after filtering. mln_ch_value(I, bool)& img() {return img_; }; private: - S sorted_sites_; tree_t tree_; mln_ch_value(I, bool) img_; @@ -68,7 +76,7 @@ void usage(char* argv[]) { - std::cerr << "usage: " << argv[0] << " input.pgm lambda1 lamda2" + std::cerr << "usage: " << argv[0] << " input.pgm accumulator lambda1 [lambda2]" << std::endl; abort(); } @@ -85,17 +93,26 @@ float lambda2; I input; - if (argc < 3) + if (argc < 4) usage(argv); io::pgm::load(input, argv[1]); - lambda1 = atof(argv[2]); - lambda2 = (argc == 4) ? atof(argv[3]) : mln_max(float); - treefilter<I> f(input, morpho::attribute::sharpness<I>(), lambda1, lambda2); + lambda1 = atof(argv[3]); + lambda2 = (argc == 5) ? atof(argv[4]) : mln_max(float); + + std::string s(argv[2]); + treefilter<I>* f = 0; + if (s == "card") + f = new treefilter<I>(input, morpho::attribute::card<I>(), lambda1, lambda2); + else if (s == "sharpness") + f = new treefilter<I>(input, morpho::attribute::sharpness<I>(), lambda1, lambda2); + else + usage(argv); - back_propagate_subbranch(f.tree(), f.img() ,true); - back_propagate_level(f.tree(), f.img()); + back_propagate_subbranch(f->tree(), f->img() ,true); + back_propagate_level(f->tree(), f->img()); - io::pbm::save(f.img(), "out.pbm"); + io::pbm::save(f->img(), "out.pbm"); + delete f; } Index: trunk/milena/sandbox/theo/rush/exo2/exo2.sh =================================================================== --- trunk/milena/sandbox/theo/rush/exo2/exo2.sh (revision 0) +++ trunk/milena/sandbox/theo/rush/exo2/exo2.sh (revision 3450) @@ -0,0 +1,16 @@ +#! /bin/bash + +if [ ! -f affiche2.pgm ]; then + echo "affiche2.pgm introuvable" + exit 1 +fi + +convert -geometry 10% affiche2.pgm temp.bmp +convert temp.bmp affiche2_10p.pgm +./exo2 affiche2_10p.pgm card -1 21 +mv out.pbm card_10p.pbm +./exo2 affiche2.pgm card 2100 3000 +mv out.pbm card.pbm +./exo2 affiche2.pgm sharpness 0.8 1 +mv out.pbm sharpness.pbm +rm temp.bmp \ No newline at end of file Property changes on: trunk/milena/sandbox/theo/rush/exo2/exo2.sh ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/theo/rush/exo2/Makefile =================================================================== --- trunk/milena/sandbox/theo/rush/exo2/Makefile (revision 3449) +++ trunk/milena/sandbox/theo/rush/exo2/Makefile (revision 3450) @@ -14,6 +14,8 @@ LDFLAGS= all: clean $(TARGET) + chmod +x exo2.sh + ./exo2.sh $(TARGET): $(OBJS) $(SRC) $(LD) $(LDFLAGS) -o $@ $(OBJS) @@ -30,3 +32,5 @@ clean: rm -f *.o $(REF) $(TARGET) + rm -f *.pbm + find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete \ No newline at end of file