r3686: Routines to export leaves toward several representation

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-19 Edwin Carlinet <carlinet@lrde.epita.fr> Routines to export leaves toward several representation. * edwin/rush/Makefile: New. * edwin/rush/chain.sh: Script that handles process. * edwin/rush/configure: New. * edwin/rush/export_leaves.hh: Leaves exportation methods. * edwin/rush/get_leaves.cc: Process file that import pgm image, creates tree, applies an attribute and export the leaves. * edwin/rush/splot.sh: New file to autogenerate gnuplot graphics. * edwin/rush/test/Makefile: New. * edwin/rush/test/configure: New. * edwin/rush/test/export.cc: Test file for routines. * edwin/rush/test: New test folder. * edwin/rush: New. * edwin/tree/propagate.hh: Add missing include. --- rush/Makefile | 35 +++++++++++++++ rush/chain.sh | 34 ++++++++++++++ rush/configure | 21 +++++++++ rush/export_leaves.hh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ rush/get_leaves.cc | 65 ++++++++++++++++++++++++++++ rush/splot.sh | 10 ++++ rush/test/Makefile | 41 +++++++++++++++++ rush/test/configure | 21 +++++++++ rush/test/export.cc | 63 +++++++++++++++++++++++++++ tree/propagate.hh | 1 10 files changed, 406 insertions(+) Index: trunk/milena/sandbox/edwin/tree/propagate.hh =================================================================== --- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3685) +++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3686) @@ -33,6 +33,7 @@ /// Functions to propagate a node value in the tree. #include <mln/morpho/tree/data.hh> +# include "propagate_node.hh" namespace mln { namespace morpho { Index: trunk/milena/sandbox/edwin/rush/test/configure =================================================================== --- trunk/milena/sandbox/edwin/rush/test/configure (revision 0) +++ trunk/milena/sandbox/edwin/rush/test/configure (revision 3686) @@ -0,0 +1,21 @@ +#! /bin/bash + +for arg in "$@"; do + if [ "$arg" == "--debug" ]; then + debug=1; + elif [ "$arg" == "--release" ]; then + release=1; + elif [ "${arg#--mln_dir=}" ]; then + MLN_DIR=${arg#--mln_dir=} + fi +done + +rm -f makefile.rules +touch makefile.rules +if [ "$debug" ]; then + echo 'DEBUG = 1' >> makefile.rules +fi +if [ "$release" ]; then + echo 'RELEASE = 1' >> makefile.rules +fi +echo "MLN_DIR = $MLN_DIR" >> makefile.rules \ No newline at end of file Property changes on: trunk/milena/sandbox/edwin/rush/test/configure ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/edwin/rush/test/export.cc =================================================================== --- trunk/milena/sandbox/edwin/rush/test/export.cc (revision 0) +++ trunk/milena/sandbox/edwin/rush/test/export.cc (revision 3686) @@ -0,0 +1,63 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library 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 this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library 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/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/level/sort_psites.hh> + +#include <mln/morpho/tree/data.hh> +#include "../export_leaves.hh" + +#include <mln/io/pbm/save.hh> + + +int main() +{ + using namespace mln; + + typedef image2d<int> I; + typedef p_array<point2d> S; + typedef morpho::tree::data<I,S> tree_t; + + int vals[] = {3, 3, 4, + 3, 5, 4, + 4, 4, 4 }; + + I ima = make::image2d(vals); + S s = level::sort_psites_decreasing(ima); + tree_t t(ima, s, c4()); + + export_leaves_to_file(t, ima); + + typedef mln_ch_value_(I, bool) B; + B b_img = export_leaves_to_img(t, ima); + + io::pbm::save(b_img, "leaves.pbm"); +} Index: trunk/milena/sandbox/edwin/rush/test/Makefile =================================================================== --- trunk/milena/sandbox/edwin/rush/test/Makefile (revision 0) +++ trunk/milena/sandbox/edwin/rush/test/Makefile (revision 3686) @@ -0,0 +1,41 @@ +include makefile.rules +TARGET=export +#sharp_SRC=sharp.cc +#sharp_OBJS=${sharp_SRC:.cc=.o} + +export_SRC=export.cc +export_OBJS=${export_SRC:.cc=.o} + +OLENADIR=$(MLN_DIR)/.. +MILENADIR=$(MLN_DIR) + +CXXFLAGS=-I$(MILENADIR) -I./ -W -Wall + + +CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\ + $(if $(RELEASE), -O3, -O1)) + +CXX=g++ +LD=g++ +LDFLAGS= + +all: $(TARGET) + + +$(TARGET): $($(TARGET)_OBJS) $($(TARGET)_SRC) + $(LD) $(LDFLAGS) -o $@ $($(TARGET)_OBJS) + +%.o: %.cc + $(CXX) $(CXXFLAGS) -c $< + +%.o: %.hh + $(CXX) $(CXXFLAGS) -c $< + +depend: + makedepend -- $(CXXFLAGS) -- -v $($(TARGET)_SRC) + +clean: + rm -f *.o $(TARGET) + #rm -f *.pbm + #find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete +# DO NOT DELETE \ No newline at end of file Index: trunk/milena/sandbox/edwin/rush/configure =================================================================== --- trunk/milena/sandbox/edwin/rush/configure (revision 0) +++ trunk/milena/sandbox/edwin/rush/configure (revision 3686) @@ -0,0 +1,21 @@ +#! /bin/bash + +for arg in "$@"; do + if [ "$arg" == "--debug" ]; then + debug=1; + elif [ "$arg" == "--release" ]; then + release=1; + elif [ "${arg#--mln_dir=}" ]; then + MLN_DIR=${arg#--mln_dir=} + fi +done + +rm -f makefile.rules +touch makefile.rules +if [ "$debug" ]; then + echo 'DEBUG = 1' >> makefile.rules +fi +if [ "$release" ]; then + echo 'RELEASE = 1' >> makefile.rules +fi +echo "MLN_DIR = $MLN_DIR" >> makefile.rules \ No newline at end of file Property changes on: trunk/milena/sandbox/edwin/rush/configure ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/edwin/rush/get_leaves.cc =================================================================== --- trunk/milena/sandbox/edwin/rush/get_leaves.cc (revision 0) +++ trunk/milena/sandbox/edwin/rush/get_leaves.cc (revision 3686) @@ -0,0 +1,65 @@ +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/core/site_set/p_array.hh> + +#include <mln/level/sort_psites.hh> + +#include <mln/morpho/tree/data.hh> +#include <mln/morpho/tree/compute_attribute_image.hh> +#include "export_leaves.hh" + +#include <mln/morpho/attribute/sharpness.hh> + +#include <mln/io/pbm/save.hh> +#include <mln/io/pgm/load.hh> + +#include <mln/value/int_u8.hh> + +#include <iostream> + + + +void usage(char** argv) +{ + std::cout << "Retrieve leaves of the component tree using sharpness" + << " attribute. It returns a binary image of leaves and creates" + << " txt file that contains nodes of the branch that the leaf belongs to." + << std::endl; + std::cout << "Usage: " << argv[0] << " input.pgm" << std::endl; + abort(); +} + + +int main(int argc, char* argv[]) +{ + using namespace mln; + using value::int_u8; + + if (argc == 0) + usage(argv); + + + // Load a pgm img (Gray level Or Gradient Image) + typedef image2d<int_u8> I; + I input; + io::pgm::load(input, argv[1]); + + // Tree Creation + typedef p_array<point2d> S; + typedef morpho::tree::data<I,S> tree_t; + S s = level::sort_psites_decreasing(input); + tree_t t(input, s, c4()); + + // Attribute pruning. + typedef morpho::attribute::sharpness<I> sharp_t; + typedef mln_ch_value_(I, double) A; + + A a = morpho::tree::compute_attribute_image(sharp_t (), t); + + + //Export Leaves + typedef mln_ch_value_(I, bool) B; + B b_img = export_leaves_to_img(t, a); + io::pbm::save(b_img, "leaves.pbm"); + export_leaves_to_file(t, a); +} Index: trunk/milena/sandbox/edwin/rush/splot.sh =================================================================== --- trunk/milena/sandbox/edwin/rush/splot.sh (revision 0) +++ trunk/milena/sandbox/edwin/rush/splot.sh (revision 3686) @@ -0,0 +1,10 @@ +#! /bin/bash +FILE=gplot.batch + +echo "set terminal png" > "$FILE" +for f in *.txt; do + echo 'set output "'$f'.png"' >> "$FILE" + echo 'plot "'$f'"' >> "$FILE" +done; + +gnuplot "$FILE" \ No newline at end of file Property changes on: trunk/milena/sandbox/edwin/rush/splot.sh ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/edwin/rush/chain.sh =================================================================== --- trunk/milena/sandbox/edwin/rush/chain.sh (revision 0) +++ trunk/milena/sandbox/edwin/rush/chain.sh (revision 3686) @@ -0,0 +1,34 @@ +#! /bin/bash + +function usage() +{ +echo "./chain.sh input.ppm (--graylevel | --gradient)" +exit 2 +} + +if [ $# -ne 2 ]; then + usage +fi + +if [ "$2" = "--gradient" ]; then + gradient=1 +elif [ "$2" = "--graylevel" ]; then + graylevel=1 +else + usage +fi + +make leaves +if [ "x$gradient" = "x1" ]; then + make all + name="gradient.pgm" + ./gradient "$1" "$name" +else + name="$1" + name="${name%.ppm}.pgm" + convert +compress -depth 8 -colorspace Gray "$1" "$name" +fi +./leaves "$name" +rm -Rf "$1".dir +mkdir "$1".dir +mv *.txt "leaves.pbm" "$name" "$1".dir \ No newline at end of file Property changes on: trunk/milena/sandbox/edwin/rush/chain.sh ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/edwin/rush/Makefile =================================================================== --- trunk/milena/sandbox/edwin/rush/Makefile (revision 0) +++ trunk/milena/sandbox/edwin/rush/Makefile (revision 3686) @@ -0,0 +1,35 @@ +include makefile.rules + + +OLENADIR=$(MLN_DIR)/.. +MILENADIR=$(MLN_DIR) + +CXXFLAGS = -I$(MILENADIR) -I./ -W -Wall +CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\ + $(if $(RELEASE), -O3, -O1)) +CXX=g++ +LD=g++ +LDFLAGS= +SRC= + + +GRADIENT_SRC = $(MLN_DIR)/sandbox/theo/exec/color_internal_gradient.cc +LEAVES_SRC = get_leaves.cc + + +all: leaves gradient + + +leaves: $(LEAVES_SRC) + $(CXX) $(CXXFLAGS) $< -o leaves + +gradient: $(GRADIENT_SRC) + $(CXX) $(CXXFLAGS) $< -o gradient + + +clean: + rm -f leaves gradient + + +%.o: %.cc + $(CXX) $(CXXFLAGS) -c $< \ No newline at end of file Index: trunk/milena/sandbox/edwin/rush/export_leaves.hh =================================================================== --- trunk/milena/sandbox/edwin/rush/export_leaves.hh (revision 0) +++ trunk/milena/sandbox/edwin/rush/export_leaves.hh (revision 3686) @@ -0,0 +1,115 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library 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 this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library 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. + +#ifndef EXPORT_LEAVES_HH_ +# define EXPORT_LEAVES_HH_ + +# include <mln/core/concept/image.hh> + +# include <mln/morpho/tree/data.hh> +# include "../tree/propagate.hh" + + +# include <mln/data/fill.hh> + +# include <fstream> +# include <sstream> + +namespace mln { + + template <typename T, typename A> + inline + void + export_leaves_to_file(const T& tree, const Image<A>& attr_image); + + template <typename T, typename A> + inline + mln_ch_value(A, bool) + export_leaves_to_img(const T& tree, const Image<A>& attr_image); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T, typename A> + inline + void + export_leaves_to_file(const T& tree, const Image<A>& attr_image) + { + mln_precondition(tree.f().domain() == attr_image.domain()); + + const A& a = exact(attr_image); + mln_leaf_piter(T) leaf(tree); + + for_all(leaf) + { + std::stringstream fn; + for (int i = 0; i < leaf.dim; i++) + fn << "[" << leaf[i] << "]"; + fn << ".txt"; + + std::ofstream out(fn.str().c_str()); + mln_psite(T) n = leaf; + int i = 0; + while (!tree.is_root(n)) + { + out << i++ << " " << a(n) << std::endl; + n = tree.parent(n); + } + out << i << " " << a(n) << std::endl; + } + } + + template <typename T, typename A> + inline + mln_ch_value(A, bool) + export_leaves_to_img(const T& tree, const Image<A>& attr_image) + { + mln_precondition(tree.f().domain() == attr_image.domain()); + + typedef mln_ch_value(A, bool) I; + const A& a = exact(attr_image); + + I output; + initialize(output, a); + data::fill(output, false); + + mln_leaf_piter(T) l(tree); + for_all(l) + output(l) = true; + + morpho::tree::propagate_representant(tree, output); + return output; + } + + + +# endif /* !MLN_INCLUDE_ONLY */ + +} // end of namespace mln + +#endif /* !EXPORT_LEAVES_HH_ */
participants (1)
-
Edwin Carlinet