https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Area closing/opening for line graph images based on adjacent
vertices.
* mln/core/line_graph_psite.hh
(mln::line_graph_psite<P>::first_id)
(mln::line_graph_psite<P>::second_id):
New methods.
Use them to simplify...
(mln::line_graph_psite<P>::first)
(mln::line_graph_psite<P>::second): ...these ones.
* mln/accu/count_adjacent_vertices.hh: New accumulator.
* mln/morpho/closing_area_on_vertices.hh,
* mln/morpho/opening_area_on_vertices.hh:
New filters.
* mln/morpho/closing_area.hh,
* mln/morpho/opening_area.hh,
* mln/morpho/closing_attribute.hh,
* mln/morpho/opening_attribute.hh:
Remove spurious comments.
* tests/morpho/lena_line_graph_image_wst2.cc: Use
morpho::closing_area_on_vertices instead of morpho::closing.
mln/accu/count_adjacent_vertices.hh | 113 +++++++++++++++++------------
mln/core/line_graph_psite.hh | 32 +++++++-
mln/morpho/closing_area.hh | 5 -
mln/morpho/closing_area_on_vertices.hh | 39 ++++------
mln/morpho/closing_attribute.hh | 5 -
mln/morpho/opening_area.hh | 5 -
mln/morpho/opening_area_on_vertices.hh | 38 ++++-----
mln/morpho/opening_attribute.hh | 5 -
tests/morpho/lena_line_graph_image_wst2.cc | 16 +---
9 files changed, 138 insertions(+), 120 deletions(-)
Index: mln/core/line_graph_psite.hh
--- mln/core/line_graph_psite.hh (revision 1801)
+++ mln/core/line_graph_psite.hh (working copy)
@@ -79,11 +79,16 @@
/// Return the edge id of this point site.
util::edge_id id() const;
- /// Return the first associated point (vertex).
+ /// Return the first associated vertex.
P first() const;
- /// Return the second associated point (vertex).
+ /// Return the second associated vertex.
P second() const;
+ /// Return the id of the first associated vertex.
+ util::node_id first_id() const;
+ /// Return the id of the second associated vertex.
+ util::node_id second_id() const;
+
private:
/// Is this psite valid?
bool is_valid_() const;
@@ -228,7 +233,7 @@
line_graph_psite<P>::first() const
{
mln_assertion(is_valid_());
- return plg().gr_->node_data(plg().gr_->edge(id_).n1());
+ return plg().gr_->node_data(first_id());
}
template<typename P>
@@ -237,7 +242,26 @@
line_graph_psite<P>::second() const
{
mln_assertion(is_valid_());
- return plg().gr_->node_data(plg().gr_->edge(id_).n2());
+ return plg().gr_->node_data(second_id());
+ }
+
+
+ template<typename P>
+ inline
+ util::node_id
+ line_graph_psite<P>::first_id() const
+ {
+ mln_assertion(is_valid_());
+ return plg().gr_->edge(id_).n1();
+ }
+
+ template<typename P>
+ inline
+ util::node_id
+ line_graph_psite<P>::second_id() const
+ {
+ mln_assertion(is_valid_());
+ return plg().gr_->edge(id_).n2();
}
Index: mln/accu/count_adjacent_vertices.hh
--- mln/accu/count_adjacent_vertices.hh (revision 1801)
+++ mln/accu/count_adjacent_vertices.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -25,17 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_ACCU_COUNT_HH
-# define MLN_ACCU_COUNT_HH
+#ifndef MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
+# define MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
-/*! \file mln/accu/count.hh
- *
- * \brief Define an accumulator that counts.
- */
+/// \file mln/accu/count_adjacent_vertices.hh
+/// \brief Define an accumulator that counts the vertices adjacent to a
+/// set of line graph psite.
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
-
+# include <mln/core/line_graph_image.hh>
+# include <mln/util/pix.hh>
namespace mln
{
@@ -43,96 +43,119 @@
namespace accu
{
-
- /*!
- * \brief Generic counter accumulator class.
- *
- * The parameter \a T is the type to be count.
- */
- template <typename T>
- struct count_ : public mln::accu::internal::base_< std::size_t , count_<T>
>
+ /// \brief Accumulator class counting the number of vertices
+ /// adjacent to a set of mln::line_graph_psite (i.e., a set of
+ /// edges).
+ ///
+ /// The type to be count is mln::util::pix< mln::line_graph_image<P, V>
>
+ /// where \p P and \p V are the parameters of this class.
+ template <typename P, typename V>
+ struct count_adjacent_vertices_
+ : public mln::accu::internal::base_< std::size_t,
+ count_adjacent_vertices_<P, V> >
{
- typedef T argument;
- typedef std::size_t result; // FIXME: Up in Accumulator.
+ typedef mln::util::pix< mln::line_graph_image<P, V> > argument;
- count_();
+ count_adjacent_vertices_();
+ /// Manipulators.
+ /// \{
void init();
- // FIXME : should we add a take() without argument?
- void take(const argument&);
- void take(const count_<T>& other);
+ void take(const argument& arg);
+ void take(const count_adjacent_vertices_<P, V>& other);
- std::size_t to_result() const;
+ /// Force the value of the counter to \a c.
void set_value(std::size_t c);
+ /// \}
+
+ /// Get the value of the accumulator.
+ std::size_t to_result() const;
protected:
+ /// Update the value of the counter.
+ void update_ ();
+ protected:
+ /// The value of the counter.
std::size_t count__;
+ /// The set of adjacent vertices.
+ std::set<util::node_id> vertices_;
};
- /*!
- * \brief Meta accumulator for count.
- */
- struct count : public Meta_Accumulator< count >
+ /// \brief Meta accumulator for count_adjacent_vertices.
+ struct count_adjacent_vertices
+ : public Meta_Accumulator< count_adjacent_vertices >
{
- template <typename T>
+ template <typename P, typename V>
struct with
{
- typedef count_<T> ret;
+ typedef count_adjacent_vertices_<P, V> ret;
};
};
# ifndef MLN_INCLUDE_ONLY
- template <typename T>
+ template <typename P, typename V>
inline
- count_<T>::count_()
+ count_adjacent_vertices_<P, V>::count_adjacent_vertices_()
{
init();
}
- template <typename T>
+ template <typename P, typename V>
inline
void
- count_<T>::init()
+ count_adjacent_vertices_<P, V>::init()
{
- count__ = 0;
+ vertices_.clear();
+ update_();
}
- template <typename T>
+ template <typename P, typename V>
inline
void
- count_<T>::take(const argument&)
+ count_adjacent_vertices_<P, V>::take(const argument& arg)
{
- ++count__;
+ vertices_.insert(arg.p().first_id());
+ vertices_.insert(arg.p().second_id());
+ update_();
}
- template <typename T>
+ template <typename P, typename V>
inline
void
- count_<T>::take(const count_<T>& other)
+ count_adjacent_vertices_<P, V>::take(const count_adjacent_vertices_<P,
V>& other)
{
- count__ += other.count__;
+ vertices_.insert (other.vertices_.begin(), other.vertices_.end());
+ update_();
}
- template <typename T>
+ template <typename P, typename V>
inline
std::size_t
- count_<T>::to_result() const
+ count_adjacent_vertices_<P, V>::to_result() const
{
return count__;
}
- template <typename T>
+ template <typename P, typename V>
inline
void
- count_<T>::set_value(std::size_t c)
+ count_adjacent_vertices_<P, V>::set_value(std::size_t c)
{
count__ = c;
}
+ template <typename P, typename V>
+ inline
+ void
+ count_adjacent_vertices_<P, V>::update_()
+ {
+ count__ = vertices_.size();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
@@ -140,4 +163,4 @@
} // end of namespace mln
-#endif // ! MLN_ACCU_COUNT_HH
+#endif // ! MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
Index: mln/morpho/closing_area_on_vertices.hh
--- mln/morpho/closing_area_on_vertices.hh (revision 1801)
+++ mln/morpho/closing_area_on_vertices.hh (working copy)
@@ -25,16 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_CLOSING_AREA_HH
-# define MLN_MORPHO_CLOSING_AREA_HH
+#ifndef MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
+# define MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
-/*! \file mln/morpho/closing_area.hh
- *
- * \brief Morphological area closing.
- */
+/// \file mln/morpho/closing_area.hh
+///
+/// \brief Morphological area closing on a line graph image computing
+/// the area in terms of adjacent vertices.
+# include <mln/core/line_graph_image.hh>
# include <mln/morpho/closing_attribute.hh>
-# include <mln/accu/count.hh>
+# include <mln/accu/count_adjacent_vertices.hh>
namespace mln
@@ -43,28 +44,26 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
- /// Morphological area closing.
- template <typename I, typename N, typename O>
- void closing_area(const Image<I>& input, const Neighborhood<N>&
nbh,
+ /// Morphological area closing on a mln::line_graph_image computing
+ /// the area in terms of adjacent vertices.
+ template <typename P, typename V, typename N, typename O>
+ void closing_area_on_vertices(const line_graph_image<P, V>& input,
+ const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename N, typename O>
+ template <typename P, typename V, typename N, typename O>
inline
- void closing_area(const Image<I>& input, const Neighborhood<N>&
nbh,
+ void closing_area_on_vertices(const line_graph_image<P, V>& input,
+ const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
- typedef util::pix<I> pix_t;
+ typedef accu::count_adjacent_vertices_<P, V> attribute_t;
// FIXME: Change sig of closing_attribute!
- closing_attribute< accu::count_<pix_t> >(input, nbh, lambda, output);
+ closing_attribute<attribute_t>(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -74,4 +73,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_CLOSING_AREA_HH
+#endif // ! MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
Index: mln/morpho/opening_area_on_vertices.hh
--- mln/morpho/opening_area_on_vertices.hh (revision 1801)
+++ mln/morpho/opening_area_on_vertices.hh (working copy)
@@ -25,16 +25,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_OPENING_AREA_HH
-# define MLN_MORPHO_OPENING_AREA_HH
+#ifndef MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
+# define MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
-/*! \file mln/morpho/opening_area.hh
- *
- * \brief Morphological area opening.
- */
+/// \file mln/morpho/opening_area_on_vertices.hh
+/// \brief Morphological area opening on a line graph image computing
+/// the area in terms of adjacent vertices.
+# include <mln/core/line_graph_image.hh>
# include <mln/morpho/opening_attribute.hh>
-# include <mln/accu/count.hh>
+# include <mln/accu/count_adjacent_vertices.hh>
namespace mln
@@ -43,28 +43,26 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
- /// Morphological area opening.
- template <typename I, typename N, typename O>
- void opening_area(const Image<I>& input, const Neighborhood<N>&
nbh,
+ /// Morphological area opening on a mln::line_graph_image computing
+ /// the area in terms of adjacent vertices.
+ template <typename P, typename V, typename N, typename O>
+ void opening_area_on_vertices(const line_graph_image<P, V>& input,
+ const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename N, typename O>
+ template <typename P, typename V, typename N, typename O>
inline
- void opening_area(const Image<I>& input, const Neighborhood<N>&
nbh,
+ void opening_area_on_vertices(const line_graph_image<P, V>& input,
+ const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
- typedef util::pix<I> pix_t;
+ typedef accu::count_adjacent_vertices_<P, V> attribute_t;
// FIXME: Change sig of opening_attribute!
- opening_attribute< accu::count_<pix_t> >(input, nbh, lambda, output);
+ opening_attribute<attribute_t>(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -74,4 +72,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_OPENING_AREA_HH
+#endif // ! MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
Index: mln/morpho/closing_area.hh
--- mln/morpho/closing_area.hh (revision 1801)
+++ mln/morpho/closing_area.hh (working copy)
@@ -43,11 +43,6 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
/// Morphological area closing.
template <typename I, typename N, typename O>
void closing_area(const Image<I>& input, const Neighborhood<N>&
nbh,
Index: mln/morpho/opening_area.hh
--- mln/morpho/opening_area.hh (revision 1801)
+++ mln/morpho/opening_area.hh (working copy)
@@ -43,11 +43,6 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
/// Morphological area opening.
template <typename I, typename N, typename O>
void opening_area(const Image<I>& input, const Neighborhood<N>&
nbh,
Index: mln/morpho/closing_attribute.hh
--- mln/morpho/closing_attribute.hh (revision 1801)
+++ mln/morpho/closing_attribute.hh (working copy)
@@ -45,11 +45,6 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
/// Morphological attribute closing.
template <typename A,
typename I, typename N, typename O>
Index: mln/morpho/opening_attribute.hh
--- mln/morpho/opening_attribute.hh (revision 1801)
+++ mln/morpho/opening_attribute.hh (working copy)
@@ -45,11 +45,6 @@
namespace morpho
{
- /* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
-
/// Morphological attribute opening.
template <typename A,
typename I, typename N, typename O>
Index: tests/morpho/lena_line_graph_image_wst2.cc
--- tests/morpho/lena_line_graph_image_wst2.cc (revision 1801)
+++ tests/morpho/lena_line_graph_image_wst2.cc (working copy)
@@ -42,9 +42,9 @@
between the values on the nodes adjacent to the edge, so as to
create a (norm of the gradient) ``between the pixels'' of the
input image;
- \li (insert an minima-killer pass here, as soon as it works on
- graph-based images);
- \li perform a WST on the line graph image;
+ \li reduce the number of minima using an area opening (computing the
+ area using the vertices, not the edges);
+ \li perform a WST on this simplified line graph image;
\li reduce the quantification of the result of the WST;
\li create an 2-D, color output image with height and width double
the size the original one, and copy the data of the input image
@@ -63,7 +63,7 @@
#include <mln/core/line_graph_neighborhood_piter.hh>
#include <mln/morpho/line_gradient.hh>
-#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/closing_area_on_vertices.hh>
#include <mln/morpho/meyer_wst.hh>
#include <mln/level/stretch.hh>
@@ -114,13 +114,7 @@
nbh_t nbh;
ima_t closed_lg_ima (lg_ima.domain());
- /* FIXME: We should change the attribute closing performed here;
- instead of computing the area using the data on the lines
- (edges), whe should use the data on the pixels (vertices).
-
- The best way is probably to create another attribute-functor and
- use the algebraic_union_find canvas. */
- morpho::closing_area(lg_ima, nbh, 20, closed_lg_ima);
+ morpho::closing_area_on_vertices(lg_ima, nbh, 20, closed_lg_ima);
/*------.
| WST. |