URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-22 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Granulometry tests.
* edwin/rush/exo2/test.cc: Experimentation related to sharpness.
* edwin/rush/exo2/wst_from_tree.cc: Fix bugs linked to
sharpness attribute.
* edwin/rush/granulometry/granulometry.hh: Compute curve
number of components / attribute value.
* edwin/rush/granulometry/test.cc: Test file for granulometry.
* edwin/rush/granulometry: New.
* edwin/tree/components.hh: Minor fixes.
* edwin/tree/propagate.hh: Minor fixes.
---
rush/exo2/Makefile | 2
rush/exo2/test.cc | 131 +++++++++++++++++++++++++++++++++
rush/exo2/wst_from_tree.cc | 2
rush/granulometry/Makefile | 36 +++++++++
rush/granulometry/granulometry.hh | 149 ++++++++++++++++++++++++++++++++++++++
rush/granulometry/test.cc | 107 +++++++++++++++++++++++++++
tree/components.hh | 4 -
tree/propagate.hh | 8 +-
8 files changed, 431 insertions(+), 8 deletions(-)
Index: trunk/milena/sandbox/edwin/tree/propagate.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3698)
+++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3699)
@@ -77,16 +77,16 @@
const p_array< mln_psite(A) >& component_list,
const mln_value(A)& null)
{
- const A& attr_img = exact(attr_image);
+ const A& a = exact(attr_image);
A out;
- initialize(out, attr_img);
+ initialize(out, a);
data::fill(out, null);
mln_piter(p_array<mln_psite(A)>) p(component_list);
for_all(p)
{
- out(p) = attr_img(p);
- morpho::tree::propagate_node_to_descendants(p, tree, out);
+ out(p) = a(p);
+ morpho::tree::propagate_node_to_descendants(p, tree, out, a(p));
}
morpho::tree::propagate_representant(tree, out);
return out;
Index: trunk/milena/sandbox/edwin/tree/components.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/components.hh (revision 3698)
+++ trunk/milena/sandbox/edwin/tree/components.hh (revision 3699)
@@ -222,7 +222,7 @@
p_array< mln_psite(A) > components;
mln_ch_value(A, bool) activity;
p_array< mln_psite(A) > max_arr = tree.nodes();
- unsigned arr_pos; //position in max_array
+ unsigned arr_pos = 0; //position in max_array
unsigned n = 0;
unsigned* nb_leaves = uses_leaves ? new unsigned(0) : 0;
@@ -237,7 +237,7 @@
p = max_arr[arr_pos];
if (a(p) == 0)
break;
- //std::cout << p << " " << a(p) << std::endl;
+ std::cout << p << " " << a(p) << std::endl;
components.insert(p);
morpho::tree::propagate_node_to_descendants(p, tree, activity, false, nb_leaves);
morpho::tree::propagate_node_to_ancestors(p, tree, activity, false);
Index: trunk/milena/sandbox/edwin/rush/granulometry/test.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/granulometry/test.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/granulometry/test.cc (revision 3699)
@@ -0,0 +1,107 @@
+// 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 "granulometry.hh"
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/pgm/load.hh>
+
+#include <mln/level/sort_psites.hh>
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/morpho/attribute/card.hh>
+
+#include <mln/data/fill.hh>
+#include "../../tree/propagate_node.hh"
+
+#include <iostream>
+#include <map>
+
+void usage(char** argv)
+{
+ 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 != 2)
+ usage(argv);
+
+ typedef image2d<int_u8> I;
+ I input;
+ io::pgm::load(input, argv[1]);
+
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+
+ S s = level::sort_psites_decreasing(input);
+ tree_t tree(input, s, c4());
+
+ typedef mln_ch_value_(I, unsigned) A;
+ typedef morpho::attribute::card<I> card_t;
+ A a = morpho::tree::compute_attribute_image(card_t (), tree);
+
+
+
+ {
+ typedef std::map<mln_value_(A), unsigned> F;
+ F f = morpho::tree::compute_attribute_curve_beta(tree, a);
+
+ unsigned count;
+ mln_ch_value_(A, bool) activity;
+ initialize(activity, a);
+ F::iterator it;
+ for (it = f.begin(); it != f.end(); ++it)
+ {
+ mln_up_node_piter_(tree_t) n(tree);
+ data::fill(activity, true);
+ count = 0;
+ for_all(n)
+ if (a(n) >= it->first && activity(n))
+ {
+ morpho::tree::propagate_node_to_ancestors(n, tree, activity, false);
+ count++;
+ }
+
+ std::cout << it->first << " -> " << it->second
<< " = " << count
+ << std::endl;
+ mln_assertion(count == it->second);
+ }
+ }
+
+
+}
+
+
Index: trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh (revision 3699)
@@ -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 GRANULOMETRY_HH_
+# define GRANULOMETRY_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/site_set/p_array.hh>
+# include <mln/morpho/tree/data.hh>
+
+# include <queue>
+# include <map>
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+
+ template <typename T, typename A>
+ inline
+ std::map<mln_value(A), unsigned>
+ compute_attribute_curve_beta(const T& tree, const Image<A>&
attr_img);
+
+
+ template <typename T, typename A>
+ inline
+ std::map<mln_value(A), unsigned>
+ compute_attribute_curve(const T& tree, const Image<A>& attr_img);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal {
+
+ template <typename A>
+ struct attr_less
+ {
+ attr_less(const A& f)
+ : f_ (f)
+ {
+ }
+
+ bool operator () (const mln_psite(A)& a, const mln_psite(A)& b) const
+ {
+ return (f_(a) < f_(b));
+ }
+
+ private:
+ const A& f_;
+ };
+
+
+ }
+
+ template <typename T, typename A>
+ inline
+ std::map<mln_value(A), unsigned>
+ compute_attribute_curve(const T& tree, const Image<A>& attr_img)
+ {
+ const A& a = exact(attr_img);
+
+ std::map< mln_value(A), unsigned > f;
+ mln_node_piter(T) n(tree);
+
+ for_all(n)
+ f[a(n)]++;
+
+
+ return f;
+ }
+
+
+ template <typename T, typename A>
+ inline
+ std::map<mln_value(A), unsigned>
+ compute_attribute_curve_beta(const T& tree, const Image<A>&
attr_img)
+ {
+ const A& a = exact(attr_img);
+
+ // TODO: precondition attribut croissant
+
+
+ typedef std::priority_queue< mln_psite(A), std::vector< mln_psite(A) >,
internal::attr_less<A> > q_type;
+ std::map< mln_value(A), unsigned > f;
+ internal::attr_less<A> cmp(a);
+ q_type pqueue(cmp);
+ unsigned active_components = 1;
+
+ pqueue.push(tree.nodes()[tree.nodes().nsites() - 1]);
+
+ // TODO: push other roots
+
+ while (!pqueue.empty())
+ {
+ mln_value(A) node_v = a(pqueue.top());
+ mln_psite(A) node;
+ std::cout << pqueue.top() << " : " << node_v <<
std::endl;
+ f[node_v] = pqueue.size();
+ do {
+ ++active_components;
+ node = pqueue.top();
+ pqueue.pop();
+
+ mln_piter(p_array< mln_psite(A) >) child(tree.children(node));
+ for_all(child)
+ {
+ pqueue.push(child);
+ }
+ } while (!pqueue.empty() && a(pqueue.top()) == node_v);
+ }
+ // TODO: postcondition decroissant
+ return f;
+ }
+
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+
+#endif /* !GRANULOMETRY_HH_ */
Index: trunk/milena/sandbox/edwin/rush/granulometry/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/granulometry/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/granulometry/Makefile (revision 3699)
@@ -0,0 +1,36 @@
+include makefile.rules
+TARGET=test
+
+test_SRC=test.cc
+test_OBJS=${test_SRC:.cc=.o}
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(OLENADIR)/milena
+
+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)
Index: trunk/milena/sandbox/edwin/rush/exo2/test.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/test.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/test.cc (revision 3699)
@@ -0,0 +1,131 @@
+#include <mln/morpho/attribute/volume.hh>
+#include <mln/morpho/attribute/height.hh>
+#include <mln/morpho/attribute/sharpness.hh>
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/level/sort_psites.hh>
+#include <mln/debug/println.hh>
+
+#include <mln/convert/all.hh>
+
+#include <mln/core/image/image1d.hh>
+#include <mln/core/alias/neighb1d.hh>
+#include <mln/value/int_u8.hh>
+
+#include "../../tree/components.hh"
+#include "../../tree/propagate.hh"
+
+#include <mln/fun/p2v/ternary.hh>
+#include <mln/pw/all.hh>
+
+namespace mln
+{
+ // Sharpness Attribute -> Height Attribute
+ template <typename P2V>
+ struct height_wrapper_ : Function_p2v< height_wrapper_<P2V> >
+ {
+ typedef unsigned result;
+
+ height_wrapper_(const Function_p2v<P2V>& f) :
+ f_ (exact(f))
+ {
+ mlc_is_a(mln_result(P2V), Accumulator)::check();
+ }
+
+ template <typename P>
+ unsigned operator() (const P& p) const
+ {
+ return f_(p).height();
+ }
+
+ private:
+ const P2V& f_;
+ };
+
+ // meta
+ template <typename P2V>
+ inline
+ height_wrapper_<P2V>
+ height_wrapper(const Function_p2v<P2V>& f)
+ {
+ return height_wrapper_<P2V>(f);
+ }
+}
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+
+ const char arr[]= { 16, 0, 0, 0, 0, 15, 0, 14, 0, 0, 0, 16 };
+
+
+ typedef image1d<int_u8> I;
+ I input;
+ convert::from_to(arr, input);
+
+
+ /***************************/
+ /* Component tree creation */
+ /***************************/
+ typedef p_array<point1d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+
+ S s = level::sort_psites_decreasing(input);
+ tree_t t(input, s, c2());
+
+
+ /******************************/
+ /* Compute Attribute On Image */
+ /******************************/
+ {
+ typedef mln_ch_value_(I, unsigned) A;
+ typedef morpho::attribute::volume<I> attribute_t;
+ A a;
+
+ // Attribute Pruning
+ a = morpho::tree::compute_attribute_image(attribute_t (), t);
+ debug::println("volume", a);
+ }
+
+ mln_ch_value_(I, unsigned) height;
+ {
+ typedef mln_ch_value_(I, unsigned) A;
+ typedef morpho::attribute::height<I> attribute_t;
+
+ // Attribute Pruning
+ height = morpho::tree::compute_attribute_image(attribute_t (), t);
+ debug::println("height", height);
+ }
+
+ {
+ typedef mln_ch_value_(I, double) A;
+ typedef morpho::attribute::sharpness<I> attribute_t;
+ A a, component_img;
+
+ // Attribute Pruning
+ a = morpho::tree::compute_attribute_image(attribute_t (), t);
+ debug::println("sharpness", a);
+
+ // Component filtering
+ a = duplicate((fun::p2v::ternary(pw::value(height) > pw::cst(2),
+ pw::value(a),
+ pw::cst(0.0))) | a.domain());
+
+ debug::println("sharpness", a);
+
+
+ p_array< mln_psite_(A) > obj_array;
+ obj_array = morpho::tree::get_components(t, a);
+ std::cout << obj_array.nsites() << std::endl;
+
+ component_img = morpho::tree::propagate_components(a, t, obj_array, 0);
+
+ debug::println("sharpness", component_img);
+ }
+
+
+}
Property changes on: trunk/milena/sandbox/edwin/rush/exo2/test.cc
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 3698)
+++ trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 3699)
@@ -200,7 +200,7 @@
obj_array = morpho::tree::get_components(t, a);
std::cout << obj_array.nsites() << std::endl;
- component_img = morpho::tree::propagate_components(a, t, obj_array, 1);
+ component_img = morpho::tree::propagate_components(a, t, obj_array, 1.1);
// debug
//I output = level::stretch(int_u8(), component_img); //adapt to 0-255
Index: trunk/milena/sandbox/edwin/rush/exo2/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3698)
+++ trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3699)
@@ -13,7 +13,7 @@
SRC=
OUT_IMG=superpose.pgm mean.pgm gradient.pgm closing.pgm
-BIN=wst_from_closing wst_from_tree
+BIN=wst_from_closing wst_from_tree test
all: $(BIN)