URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-19 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Process line: watershed from color image after height closing.
* edwin/rush/*,
* edwin/rush/leaves: New directory for leaves export
routines. Move rush/* to rush/leaves.*
* edwin/rush/exo2: New.
* edwin/rush/exo2/color_internal_gradient.hh: Routine that
computes internal gradient from color image.
* edwin/rush/exo2/color_labeling_mean.hh: Routine that
replaces a basin label by its mean color.
* edwin/rush/exo2/wst_from_closing.cc: Process line.
---
exo2/Makefile | 29 +++++++
exo2/color_internal_gradient.hh | 149 ++++++++++++++++++++++++++++++++++++++++
exo2/color_labeling_mean.hh | 70 ++++++++++++++++++
exo2/configure | 21 +++++
exo2/wst_from_closing.cc | 127 ++++++++++++++++++++++++++++++++++
leaves/Makefile | 35 +++++++++
leaves/chain.sh | 34 +++++++++
leaves/configure | 21 +++++
leaves/export_leaves.hh | 115 ++++++++++++++++++++++++++++++
leaves/get_leaves.cc | 65 +++++++++++++++++
leaves/splot.sh | 10 ++
leaves/test/Makefile | 41 +++++++++++
leaves/test/configure | 21 +++++
leaves/test/export.cc | 63 ++++++++++++++++
14 files changed, 801 insertions(+)
Index: trunk/milena/sandbox/edwin/rush/configure (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/get_leaves.cc (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/splot.sh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/chain.sh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/Makefile (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/export_leaves.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/leaves/test/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/configure (revision 3687)
@@ -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/leaves/test/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/test/export.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/export.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/export.cc (revision 3687)
@@ -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/leaves/test/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/Makefile (revision 3687)
@@ -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/leaves/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/configure (revision 3687)
@@ -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/leaves/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc (revision 3687)
@@ -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/leaves/splot.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/splot.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/splot.sh (revision 3687)
@@ -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/leaves/splot.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/chain.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/chain.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/chain.sh (revision 3687)
@@ -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/leaves/chain.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/Makefile (revision 3687)
@@ -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/leaves/export_leaves.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/export_leaves.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/export_leaves.hh (revision 3687)
@@ -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_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/configure (revision 3687)
@@ -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/exo2/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc (revision 3687)
@@ -0,0 +1,127 @@
+// 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/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/label_16.hh>
+#include <mln/level/convert.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pgm/save.hh>
+
+#include "color_internal_gradient.hh"
+#include "color_labeling_mean.hh"
+#include <mln/morpho/closing/height.hh>
+#include <mln/morpho/watershed/all.hh>
+#include <mln/morpho/elementary/dilation.hh>
+
+
+#include <iostream>
+#include <string>
+
+
+void usage(char** argv)
+{
+ std::cout << "Usage: " << argv[0] << " input.ppm
height [-o1 | -o2 | -o3]"
+ << std::endl
+ << "-o1\tSuperpose WS on input image (out: superpose.ppm)" <<
std::endl
+ << "-o2\tCount number of basins" << std::endl
+ << "-o3\tReplace basin by its mean color on the input (out:
mean.ppm)"
+ << std::endl;
+ abort();
+}
+
+
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u16;
+ using value::rgb8;
+
+ if (argc < 3)
+ usage(argv);
+
+ int output_ = 0;
+ int lambda_h = std::atoi(argv[2]);
+
+ if (argc == 4)
+ if (std::string(argv[3]) == "-o1")
+ output_ = 1;
+ else if (std::string(argv[3]) == "-o2")
+ output_ = 2;
+ else if (std::string(argv[3]) == "-o3")
+ output_ = 3;
+ else
+ usage(argv);
+
+
+
+ // Load color image.
+ typedef image2d<rgb8> I_;
+ I_ input_;
+ io::ppm::load(input_, argv[1]);
+
+ // Gradient.
+ typedef image2d<int_u8> I;
+ I input = color_internal_gradient(input_);
+
+ // Closing
+ std::cout << lambda_h << std::endl;
+ input = morpho::closing::height(input, c4(), lambda_h);
+
+ // Watershed
+ typedef image2d<int_u16> WST;
+ int_u16 n_basins = 0;
+ WST wst = morpho::watershed::flooding(input, c4(), n_basins);
+
+ if (!output_ || output_ == 1)
+ {
+ I_ out = morpho::watershed::superpose(input_, wst);
+ io::ppm::save(out, "superpose.pgm");
+ }
+
+ if (!output_ || output_ == 2)
+ std::cout << "Number of basins: " << n_basins <<
std::endl;
+
+ if (!output_ || output_ == 3)
+ {
+ typedef image2d<value::label_16> L;
+ L lab = level::convert(value::label_16(),
+ morpho::elementary::dilation(wst, c8()));
+ I_ out = color_labeling_mean(input_, lab, n_basins);
+ io::ppm::save(out, "mean.pgm");
+ }
+
+}
Index: trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh (revision 3687)
@@ -0,0 +1,149 @@
+// 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 COLOR_INTERNAL_GRADIENT_HH_
+# define COLOR_INTERNAL_GRADIENT_HH_
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/morpho/elementary/gradient_internal.hh>
+#include <mln/math/diff_abs.hh>
+
+#include <mln/accu/image/init.hh>
+#include <mln/accu/image/take.hh>
+#include <mln/accu/image/to_result.hh>
+
+#include <mln/accu/max.hh>
+
+namespace mln
+{
+
+ value::int_u8
+ dist(const value::rgb8& c1,
+ const value::rgb8& c2)
+ {
+ unsigned d = 0;
+ d += math::diff_abs(c1.red(), c2.red());
+ d += math::diff_abs(c1.green(), c2.green());
+ d += math::diff_abs(c1.blue(), c2.blue());
+ if (d > 255)
+ d = 255;
+ return d;
+ }
+
+ template <typename N>
+ image2d<value::int_u8>
+ color_gradient(const image2d<value::rgb8>& input,
+ const N& nbh)
+ {
+ using value::int_u8;
+ image2d<int_u8> output(input.domain());
+
+ mln_piter(box2d) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ int_u8 d = 0u;
+ for_all(n) if (input.domain().has(n))
+ {
+ int_u8 d_ = dist(input(p), input(n));
+ if (d_ > d)
+ d = d_;
+ }
+ output(p) = d;
+ }
+
+ return output;
+ }
+
+
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_red(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().red();
+ return output;
+ }
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_green(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().green();
+ return output;
+ }
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_blue(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().blue();
+ return output;
+ }
+
+ image2d<value::int_u8>
+ color_internal_gradient(const image2d<value::rgb8>& input)
+ {
+ typedef accu::max< value::int_u8 > A;
+ image2d<A> grad(input.domain());
+
+ using morpho::elementary::gradient_internal;
+
+ accu::image::init(grad);
+
+ accu::image::take(grad,
+ gradient_internal(get_red(input), c4()));
+ accu::image::take(grad,
+ gradient_internal(get_green(input), c4()));
+ accu::image::take(grad,
+ gradient_internal(get_blue(input), c4()));
+
+ return accu::image::to_result(grad);
+ }
+
+} // mln
+
+#endif /* !COLOR_INTERNAL_GRADIENT_HH_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh (revision 3687)
@@ -0,0 +1,70 @@
+// 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 COLOR_LABELING_MEAN_HH_
+# define COLOR_LABELING_MEAN_HH_
+
+# include <mln/core/image/image2d.hh>
+
+# include <mln/labeling/compute.hh>
+# include <mln/accu/mean.hh>
+# include <mln/level/transform.hh>
+
+# include <mln/value/label_8.hh>
+# include <mln/value/int_u16.hh>
+
+namespace mln {
+
+ template <typename L>
+ image2d< value::rgb8 >
+ color_labeling_mean(const image2d< value::rgb8>& input,
+ const Image<L>& label,
+ unsigned nlabels)
+ {
+ using value::rgb8;
+ typedef algebra::vec<3,float> V;
+
+ accu::mean<value::rgb8> m_;
+ util::array<V> m = labeling::compute(m_, input, exact(label), nlabels);
+
+ util::array<rgb8> c(unsigned(nlabels) + 1);
+
+ c[0] = rgb8(0,0,0);
+ for (unsigned l = 1; l <= nlabels; ++l)
+ {
+ c[l].red() = m[l][0];
+ c[l].green() = m[l][1];
+ c[l].blue() = m[l][2];
+ }
+
+ return level::transform(label, c);
+ }
+
+} // mln
+
+#endif /* !COLOR_LABELING_MEAN_HH_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3687)
@@ -0,0 +1,29 @@
+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=
+
+OUT_IMG=superpose.pgm mean.pgm gradient.pgm closing.pgm
+
+all: wst_from_closing
+
+%: %.cc
+ $(CXX) $(CXXFLAGS) $< -o $@
+
+
+clean:
+ rm -f $(OUT_IMG)
+ rm -f wst_from_closing
+
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file