Commit c23564ba authored by Roland Levillain's avatar Roland Levillain
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1802 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent e73f399b
2008-03-25 Roland Levillain <roland@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.
2008-03-25 Roland Levillain <roland@lrde.epita.fr>
Line gradient computation.
......
// 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
// 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 MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
# define MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
/// \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
{
namespace accu
{
/// \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 mln::util::pix< mln::line_graph_image<P, V> > argument;
count_adjacent_vertices_();
/// Manipulators.
/// \{
void init();
void take(const argument& arg);
void take(const count_adjacent_vertices_<P, V>& other);
/// 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_adjacent_vertices.
struct count_adjacent_vertices
: public Meta_Accumulator< count_adjacent_vertices >
{
template <typename P, typename V>
struct with
{
typedef count_adjacent_vertices_<P, V> ret;
};
};
# ifndef MLN_INCLUDE_ONLY
template <typename P, typename V>
inline
count_adjacent_vertices_<P, V>::count_adjacent_vertices_()
{
init();
}
template <typename P, typename V>
inline
void
count_adjacent_vertices_<P, V>::init()
{
vertices_.clear();
update_();
}
template <typename P, typename V>
inline
void
count_adjacent_vertices_<P, V>::take(const argument& arg)
{
vertices_.insert(arg.p().first_id());
vertices_.insert(arg.p().second_id());
update_();
}
template <typename P, typename V>
inline
void
count_adjacent_vertices_<P, V>::take(const count_adjacent_vertices_<P, V>& other)
{
vertices_.insert (other.vertices_.begin(), other.vertices_.end());
update_();
}
template <typename P, typename V>
inline
std::size_t
count_adjacent_vertices_<P, V>::to_result() const
{
return count__;
}
template <typename P, typename V>
inline
void
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
} // end of namespace mln
#endif // ! MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
......@@ -79,11 +79,16 @@ namespace mln
/// 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 @@ namespace mln
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 @@ namespace mln
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();
}
......
......@@ -43,11 +43,6 @@ namespace mln
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,
......
// 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
// 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 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 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_adjacent_vertices.hh>
namespace mln
{
namespace morpho
{
/// 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 P, typename V, typename N, typename O>
inline
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 accu::count_adjacent_vertices_<P, V> attribute_t;
// FIXME: Change sig of closing_attribute!
closing_attribute<attribute_t>(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
......@@ -45,11 +45,6 @@ namespace mln
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>
......
......@@ -43,11 +43,6 @@ namespace mln
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,
......
// 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
// 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 MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
# define MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
/// \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_adjacent_vertices.hh>
namespace mln
{
namespace morpho
{
/// 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 P, typename V, typename N, typename O>
inline
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 accu::count_adjacent_vertices_<P, V> attribute_t;
// FIXME: Change sig of opening_attribute!
opening_attribute<attribute_t>(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_OPENING_AREA_ON_VERTICES_HH
......@@ -45,11 +45,6 @@ namespace mln
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>
......
......@@ -42,13 +42,13 @@
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
in it, interpolating inter-pixel points;
in it, interpolating inter-pixel points;
\li print the watershed on lines into that same image, and save it. */
#include <vector>
......@@ -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 @@ int main()
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. |
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment