Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
June 2008
- 9 participants
- 135 discussions
#137: Write more attribute (connected) filters
----------------------+-----------------------------------------------------
Reporter: levill_r | Owner: Olena Team
Type: task | Status: new
Priority: major | Milestone: Olena 1.0
Component: Milena | Version: 1.0
Keywords: |
----------------------+-----------------------------------------------------
For instance,
* a volume opening/closing;
* a filter based on the height of a component;
* etc.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/137>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
1
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add height closing and opening.
* mln/accu/height.hh: New.
* mln/morpho/closing_height.hh,
* mln/morpho/opening_height.hh:
New.
* tests/morpho/closing_height.cc,
* tests/morpho/opening_height.cc:
New tests.
* tests/morpho/Makefile.am (check_PROGRAMS): Add closing_height
and opening_height.
(closing_height_SOURCES, opening_height_SOURCES): New.
mln/accu/height.hh | 107 ++++++++++++++++++++++-------------------
mln/morpho/closing_height.hh | 20 +++----
mln/morpho/opening_height.hh | 20 +++----
tests/morpho/Makefile.am | 5 +
tests/morpho/closing_height.cc | 8 +--
tests/morpho/opening_height.cc | 8 +--
6 files changed, 90 insertions(+), 78 deletions(-)
Index: mln/accu/height.hh
--- mln/accu/height.hh (revision 1990)
+++ mln/accu/height.hh (working copy)
@@ -25,26 +25,27 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_ACCU_VOLUME_HH
-# define MLN_ACCU_VOLUME_HH
+#ifndef MLN_ACCU_HEIGHT_HH
+# define MLN_ACCU_HEIGHT_HH
-/** \file mln/accu/volume.hh
- \brief Define an accumulator that computes the volume of a
+/** \file mln/accu/height.hh
+ \brief Define an accumulator that computes the height of a
component through one of its pixels.
This accumulator uses an mln::util::pix (pixel) to update the
- height, area and volume information of the component.
+ height information of the component.
- The class mln/accu/volume_ is not a general-purpose accumulator;
- it is used to implement volume-based connected filters.
- \see mln::morpho::closing_volume
- \see mln::morpho::opening_volume */
+ The class mln/accu/height_ is not a general-purpose accumulator;
+ it is used to implement height-based connected filters.
+ \see mln::morpho::closing_height
+ \see mln::morpho::opening_height */
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
# include <mln/util/pix.hh>
-# include <mln/literal/zero.hh>
+# include <mln/math/min.hh>
+# include <mln/math/max.hh>
namespace mln
{
@@ -52,46 +53,56 @@
namespace accu
{
- /// \brief Volume accumulator class.
+ /// \brief Height accumulator class.
///
/// The parameter \p I is the image type on which the accumulator
/// of pixels is built.
template <typename I>
- struct volume_
- : public mln::accu::internal::base_< std::size_t , volume_<I> >
+ struct height_
+ : public mln::accu::internal::base_< std::size_t , height_<I> >
{
/// \brief The accumulated data type.
///
- /// The volume of component is represented by the volume of its
- /// root pixel. See mln::morpho::closing_volume and
- /// mln::morpho::opening_volume for actual uses of this
+ /// The height of component is represented by the height of its
+ /// root pixel. See mln::morpho::closing_height and
+ /// mln::morpho::opening_height for actual uses of this
/// accumulator.
typedef util::pix<I> argument;
- typedef std::size_t result; // FIXME: Up in Accumulator.
+ /// The value type associated to the pixel type.
+ typedef typename argument::value value;
- volume_();
+ height_();
+ /// Manipulators.
+ /// \{
void init();
void take(const argument&);
- void take(const volume_<I>& other);
+ void take(const height_<I>& other);
+ /// Force the value of the counter to \a h.
+ void set_value(std::size_t h);
+ /// \}
+
+ /// Get the value of the accumulator.
std::size_t to_result() const;
- void set_value(std::size_t c);
protected:
- typename argument::value height__;
- std::size_t area__;
- std::size_t volume__;
+ /// The minimum level in the component.
+ value min_level__;
+ /// The maximum level in the component.
+ value max_level__;
+ /// The height of the component.
+ std::size_t height__;
};
- /// \brief Meta accumulator for volume.
- struct volume : public Meta_Accumulator< volume >
+ /// \brief Meta accumulator for height.
+ struct height : public Meta_Accumulator< height >
{
template <typename I>
struct with
{
- typedef volume_<I> ret;
+ typedef height_<I> ret;
};
};
@@ -100,7 +111,7 @@
template <typename I>
inline
- volume_<I>::volume_()
+ height_<I>::height_()
{
init();
}
@@ -108,52 +119,50 @@
template <typename I>
inline
void
- volume_<I>::init()
+ height_<I>::init()
{
- height__ = literal::zero;
- volume__ = 0;
- volume__ = 0;
+ min_level__ = mln_max(value);
+ max_level__ = mln_min(value);
+ height__ = 0;
}
template <typename I>
inline
void
- volume_<I>::take(const argument& t)
+ height_<I>::take(const argument& t)
{
- height__ = t.v();
- ++area__;
- ++volume__;
+ min_level__ = math::min(min_level__, t.v());
+ max_level__ = math::max(max_level__, t.v());
+ height__ = max_level__ - min_level__;
}
template <typename I>
inline
void
- volume_<I>::take(const volume_<I>& other)
+ height_<I>::take(const height_<I>& other)
{
- area__ += other.area__;
- /* FIXME: Is it `t.area__' or `area__' ? Th�o said it was
- the latter, but both the ISMM 2005 paper and Olena 0.11 use
- the former. */
- volume__ +=
- other.volume__ + other.area__ * math::abs(other.height__ - height__);
- // Member height__ is not touched.
+ min_level__ = math::min(min_level__, other.min_level__);
+ max_level__ = math::max(max_level__, other.max_level__);
+ height__ = max_level__ - min_level__;
}
template <typename I>
inline
std::size_t
- volume_<I>::to_result() const
+ height_<I>::to_result() const
{
- return volume__;
+ return height__;
}
template <typename I>
inline
void
- volume_<I>::set_value(std::size_t c)
+ height_<I>::set_value(std::size_t h)
{
- volume__ = c;
- // FIXME: What about area__ and height__ ?
+ height__ = h;
+ // Reset the other members.
+ min_level__ = mln_max(value);
+ max_level__ = mln_min(value);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -163,4 +172,4 @@
} // end of namespace mln
-#endif // ! MLN_ACCU_VOLUME_HH
+#endif // ! MLN_ACCU_HEIGHT_HH
Index: mln/morpho/closing_height.hh
--- mln/morpho/closing_height.hh (revision 1990)
+++ mln/morpho/closing_height.hh (working copy)
@@ -25,14 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_CLOSING_VOLUME_HH
-# define MLN_MORPHO_CLOSING_VOLUME_HH
+#ifndef MLN_MORPHO_CLOSING_HEIGHT_HH
+# define MLN_MORPHO_CLOSING_HEIGHT_HH
-/// \file mln/morpho/closing_volume.hh
-/// \brief Morphological volume closing.
+/// \file mln/morpho/closing_height.hh
+/// \brief Morphological height closing.
# include <mln/morpho/closing_attribute.hh>
-# include <mln/accu/volume.hh>
+# include <mln/accu/height.hh>
namespace mln
@@ -41,9 +41,9 @@
namespace morpho
{
- /// Morphological volume closing.
+ /// Morphological height closing.
template <typename I, typename N, typename O>
- void closing_volume(const Image<I>& input, const Neighborhood<N>& nbh,
+ void closing_height(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
@@ -51,12 +51,12 @@
template <typename I, typename N, typename O>
inline
- void closing_volume(const Image<I>& input, const Neighborhood<N>& nbh,
+ void closing_height(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
// FIXME: Change sig of closing_attribute!
- closing_attribute< accu::volume_<I> >(input, nbh, lambda, output);
+ closing_attribute< accu::height_<I> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -66,4 +66,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_CLOSING_VOLUME_HH
+#endif // ! MLN_MORPHO_CLOSING_HEIGHT_HH
Index: mln/morpho/opening_height.hh
--- mln/morpho/opening_height.hh (revision 1990)
+++ mln/morpho/opening_height.hh (working copy)
@@ -25,14 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_OPENING_VOLUME_HH
-# define MLN_MORPHO_OPENING_VOLUME_HH
+#ifndef MLN_MORPHO_OPENING_HEIGHT_HH
+# define MLN_MORPHO_OPENING_HEIGHT_HH
-/// \file mln/morpho/opening_volume.hh
-/// \brief Morphological volume opening.
+/// \file mln/morpho/opening_height.hh
+/// \brief Morphological height opening.
# include <mln/morpho/opening_attribute.hh>
-# include <mln/accu/volume.hh>
+# include <mln/accu/height.hh>
namespace mln
@@ -41,9 +41,9 @@
namespace morpho
{
- /// Morphological volume opening.
+ /// Morphological height opening.
template <typename I, typename N, typename O>
- void opening_volume(const Image<I>& input, const Neighborhood<N>& nbh,
+ void opening_height(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
@@ -51,12 +51,12 @@
template <typename I, typename N, typename O>
inline
- void opening_volume(const Image<I>& input, const Neighborhood<N>& nbh,
+ void opening_height(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
// FIXME: Change sig of opening_attribute!
- opening_attribute< accu::volume_<I> >(input, nbh, lambda, output);
+ opening_attribute< accu::height_<I> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -66,4 +66,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_OPENING_VOLUME_HH
+#endif // ! MLN_MORPHO_OPENING_HEIGHT_HH
Index: tests/morpho/closing_height.cc
--- tests/morpho/closing_height.cc (revision 1990)
+++ tests/morpho/closing_height.cc (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/morpho/closing_volume.cc
-/// \brief Test on mln::morpho::closing_volume.
+/// \file tests/morpho/closing_height.cc
+/// \brief Test on mln::morpho::closing_height.
#include <mln/core/image2d.hh>
#include <mln/value/int_u8.hh>
@@ -35,7 +35,7 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/morpho/closing_volume.hh>
+#include <mln/morpho/closing_height.hh>
#include "tests/data.hh"
@@ -48,6 +48,6 @@
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
image2d<int_u8> out(lena.domain());
- morpho::closing_volume(lena, c4(), 10000, out);
+ morpho::closing_height(lena, c4(), 20, out);
io::pgm::save(out, "out.pgm");
}
Index: tests/morpho/opening_height.cc
--- tests/morpho/opening_height.cc (revision 1990)
+++ tests/morpho/opening_height.cc (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/morpho/opening_volume.cc
-/// \brief Test on mln::morpho::opening_volume.
+/// \file tests/morpho/opening_height.cc
+/// \brief Test on mln::morpho::opening_height.
#include <mln/core/image2d.hh>
#include <mln/value/int_u8.hh>
@@ -35,7 +35,7 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/morpho/opening_volume.hh>
+#include <mln/morpho/opening_height.hh>
#include "tests/data.hh"
@@ -48,6 +48,6 @@
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
image2d<int_u8> out(lena.domain());
- morpho::opening_volume(lena, c4(), 10000, out);
+ morpho::opening_height(lena, c4(), 20, out);
io::pgm::save(out, "out.pgm");
}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1990)
+++ tests/morpho/Makefile.am (working copy)
@@ -5,6 +5,7 @@
check_PROGRAMS = \
artificial_line_graph_image_wst \
closing_area \
+ closing_height \
closing_volume \
combined \
contrast \
@@ -20,6 +21,7 @@
meyer_wst \
meyer_wst_long \
opening_area \
+ opening_height \
opening_volume \
thinning
@@ -35,7 +37,8 @@
opening_area_SOURCES = opening_area.cc
closing_area_SOURCES = closing_area.cc
-
+closing_height_SOURCES = closing_height.cc
+opening_height_SOURCES = opening_height.cc
closing_volume_SOURCES = closing_volume.cc
opening_volume_SOURCES = opening_volume.cc
1
0
03 Jun '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Revamp and specialize mln::accu::volume_.
* mln/accu/volume.hh (mln::accu::volume_<I>): Take an image
instead of a data type as parameter, and always work with a
mln::util::pix<I> instead of a free type.
(mln::accu::volume_<I>::argument): Change typedef from `T' to
`mln::util::pix<I>'.
(mln::accu::volume)
(mln::accu::volume<I>_::volume_)
(mln::accu::volume<I>_::take (const argument&))
(mln::accu::volume<I>_::take (const volume_<I>&))
(mln::accu::volume<I>_::init)
(mln::accu::volume<I>_::to_result)
(mln::accu::volume<I>_::set_value):
Adjust.
* mln/morpho/closing_volume.hh (mln::morpho::opening_volume)
* mln/morpho/opening_volume.hh (mln::morpho::closing_volume):
Adjust.
accu/volume.hh | 72 ++++++++++++++++++++++++-----------------------
morpho/closing_volume.hh | 3 -
morpho/opening_volume.hh | 3 -
3 files changed, 39 insertions(+), 39 deletions(-)
Index: mln/accu/volume.hh
--- mln/accu/volume.hh (revision 1989)
+++ mln/accu/volume.hh (working copy)
@@ -29,14 +29,21 @@
# define MLN_ACCU_VOLUME_HH
/** \file mln/accu/volume.hh
- \brief Define an accumulator that computes a volume.
+ \brief Define an accumulator that computes the volume of a
+ component through one of its pixels.
+ This accumulator uses an mln::util::pix (pixel) to update the
+ height, area and volume information of the component.
+
+ The class mln/accu/volume_ is not a general-purpose accumulator;
+ it is used to implement volume-based connected filters.
\see mln::morpho::closing_volume
\see mln::morpho::opening_volume */
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/util/pix.hh>
# include <mln/literal/zero.hh>
namespace mln
@@ -45,33 +52,33 @@
namespace accu
{
-
- /* FIXME: We should probably ``inline'' the parameter T of the
- sole use of accu::volume_ (in volume closing and opening, where
- T = util::pix<I>), since volume is not as generic as
- accu::count_, for instance. Hence, we would get rid of the
- FIXME of this file on the constraints on T. */
-
- /// \brief Generic volume accumulator class.
- /// The parameter \p T is the type of value whose volume is computed.
- template <typename T>
+ /// \brief Volume accumulator class.
+ ///
+ /// The parameter \p I is the image type on which the accumulator
+ /// of pixels is built.
+ template <typename I>
struct volume_
- : public mln::accu::internal::base_< std::size_t , volume_<T> >
+ : public mln::accu::internal::base_< std::size_t , volume_<I> >
{
- typedef T argument;
+ /// \brief The accumulated data type.
+ ///
+ /// The volume of component is represented by the volume of its
+ /// root pixel. See mln::morpho::closing_volume and
+ /// mln::morpho::opening_volume for actual uses of this
+ /// accumulator.
+ typedef util::pix<I> argument;
typedef std::size_t result; // FIXME: Up in Accumulator.
volume_();
void init();
void take(const argument&);
- void take(const volume_<T>& other);
+ void take(const volume_<I>& other);
std::size_t to_result() const;
void set_value(std::size_t c);
protected:
- // FIXME: This attributes expects a typedef `value' from T.
typename argument::value height__;
std::size_t area__;
std::size_t volume__;
@@ -81,74 +88,69 @@
/// \brief Meta accumulator for volume.
struct volume : public Meta_Accumulator< volume >
{
- template <typename T>
+ template <typename I>
struct with
{
- typedef volume_<T> ret;
+ typedef volume_<I> ret;
};
};
# ifndef MLN_INCLUDE_ONLY
- template <typename T>
+ template <typename I>
inline
- volume_<T>::volume_()
+ volume_<I>::volume_()
{
init();
}
- template <typename T>
+ template <typename I>
inline
void
- volume_<T>::init()
+ volume_<I>::init()
{
height__ = literal::zero;
volume__ = 0;
volume__ = 0;
}
- template <typename T>
+ template <typename I>
inline
void
- volume_<T>::take(const argument& t)
+ volume_<I>::take(const argument& t)
{
- /* FIXME: This accumulator will only work with types T providing
- a method v() (e.g., a util::pix<I>). */
height__ = t.v();
++area__;
++volume__;
}
- template <typename T>
+ template <typename I>
inline
void
- volume_<T>::take(const volume_<T>& other)
+ volume_<I>::take(const volume_<I>& other)
{
- // Member height__ is not touched.
-
- /* FIXME: This accumulator will only work with types T providing
- a method v() (e.g., a util::pix<I>). */
area__ += other.area__;
/* FIXME: Is it `t.area__' or `area__' ? Th�o said it was
the latter, but both the ISMM 2005 paper and Olena 0.11 use
the former. */
volume__ +=
other.volume__ + other.area__ * math::abs(other.height__ - height__);
+ // Member height__ is not touched.
}
- template <typename T>
+ template <typename I>
inline
std::size_t
- volume_<T>::to_result() const
+ volume_<I>::to_result() const
{
return volume__;
}
- template <typename T>
+ template <typename I>
inline
void
- volume_<T>::set_value(std::size_t c)
+ volume_<I>::set_value(std::size_t c)
{
volume__ = c;
// FIXME: What about area__ and height__ ?
Index: mln/morpho/closing_volume.hh
--- mln/morpho/closing_volume.hh (revision 1989)
+++ mln/morpho/closing_volume.hh (working copy)
@@ -55,9 +55,8 @@
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
- typedef util::pix<I> pix_t;
// FIXME: Change sig of closing_attribute!
- closing_attribute< accu::volume_<pix_t> >(input, nbh, lambda, output);
+ closing_attribute< accu::volume_<I> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/morpho/opening_volume.hh
--- mln/morpho/opening_volume.hh (revision 1989)
+++ mln/morpho/opening_volume.hh (working copy)
@@ -55,9 +55,8 @@
std::size_t lambda, Image<O>& output)
{
mln_precondition(exact(output).domain() == exact(input).domain());
- typedef util::pix<I> pix_t;
// FIXME: Change sig of opening_attribute!
- opening_attribute< accu::volume_<pix_t> >(input, nbh, lambda, output);
+ opening_attribute< accu::volume_<I> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add volume closing and opening.
* mln/accu/volume.hh: New.
* mln/morpho/closing_volume.hh,
* mln/morpho/opening_volume.hh:
New.
* mln/morpho/closing_attribute.hh
(mln::morho::impl::closing_attribute_tinit): Add a FIXME.
* mln/morpho/opening_attribute.hh: Aesthetic changes.
* tests/morpho/closing_volume.cc,
* tests/morpho/opening_volume.cc:
New tests.
* tests/morpho/Makefile.am (check_PROGRAMS): Add closing_volume.
(closing_volume_SOURCES): New.
mln/accu/volume.hh | 91 ++++++++++++++++++++++++----------------
mln/morpho/closing_attribute.hh | 11 +++-
mln/morpho/closing_volume.hh | 22 ++++-----
mln/morpho/opening_attribute.hh | 6 --
mln/morpho/opening_volume.hh | 22 ++++-----
tests/morpho/Makefile.am | 5 ++
tests/morpho/closing_volume.cc | 12 +----
tests/morpho/opening_volume.cc | 12 +----
8 files changed, 98 insertions(+), 83 deletions(-)
Index: mln/accu/volume.hh
--- mln/accu/volume.hh (revision 1988)
+++ mln/accu/volume.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,19 @@
// 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_VOLUME_HH
+# define MLN_ACCU_VOLUME_HH
-/*! \file mln/accu/count.hh
- *
- * \brief Define an accumulator that counts.
- */
+/** \file mln/accu/volume.hh
+ \brief Define an accumulator that computes a volume.
+
+ \see mln::morpho::closing_volume
+ \see mln::morpho::opening_volume */
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/literal/zero.hh>
namespace mln
{
@@ -44,42 +46,45 @@
{
- /*!
- * \brief Generic counter accumulator class.
- *
- * The parameter \a T is the type to be count.
- */
+ /* FIXME: We should probably ``inline'' the parameter T of the
+ sole use of accu::volume_ (in volume closing and opening, where
+ T = util::pix<I>), since volume is not as generic as
+ accu::count_, for instance. Hence, we would get rid of the
+ FIXME of this file on the constraints on T. */
+
+ /// \brief Generic volume accumulator class.
+ /// The parameter \p T is the type of value whose volume is computed.
template <typename T>
- struct count_ : public mln::accu::internal::base_< std::size_t , count_<T> >
+ struct volume_
+ : public mln::accu::internal::base_< std::size_t , volume_<T> >
{
typedef T argument;
typedef std::size_t result; // FIXME: Up in Accumulator.
- count_();
+ volume_();
void init();
- // FIXME : should we add a take() without argument?
void take(const argument&);
- void take(const count_<T>& other);
+ void take(const volume_<T>& other);
std::size_t to_result() const;
void set_value(std::size_t c);
protected:
-
- std::size_t count__;
+ // FIXME: This attributes expects a typedef `value' from T.
+ typename argument::value height__;
+ std::size_t area__;
+ std::size_t volume__;
};
- /*!
- * \brief Meta accumulator for count.
- */
- struct count : public Meta_Accumulator< count >
+ /// \brief Meta accumulator for volume.
+ struct volume : public Meta_Accumulator< volume >
{
template <typename T>
struct with
{
- typedef count_<T> ret;
+ typedef volume_<T> ret;
};
};
@@ -88,7 +93,7 @@
template <typename T>
inline
- count_<T>::count_()
+ volume_<T>::volume_()
{
init();
}
@@ -96,41 +101,57 @@
template <typename T>
inline
void
- count_<T>::init()
+ volume_<T>::init()
{
- count__ = 0;
+ height__ = literal::zero;
+ volume__ = 0;
+ volume__ = 0;
}
template <typename T>
inline
void
- count_<T>::take(const argument&)
+ volume_<T>::take(const argument& t)
{
- ++count__;
+ /* FIXME: This accumulator will only work with types T providing
+ a method v() (e.g., a util::pix<I>). */
+ height__ = t.v();
+ ++area__;
+ ++volume__;
}
template <typename T>
inline
void
- count_<T>::take(const count_<T>& other)
+ volume_<T>::take(const volume_<T>& other)
{
- count__ += other.count__;
+ // Member height__ is not touched.
+
+ /* FIXME: This accumulator will only work with types T providing
+ a method v() (e.g., a util::pix<I>). */
+ area__ += other.area__;
+ /* FIXME: Is it `t.area__' or `area__' ? Th�o said it was
+ the latter, but both the ISMM 2005 paper and Olena 0.11 use
+ the former. */
+ volume__ +=
+ other.volume__ + other.area__ * math::abs(other.height__ - height__);
}
template <typename T>
inline
std::size_t
- count_<T>::to_result() const
+ volume_<T>::to_result() const
{
- return count__;
+ return volume__;
}
template <typename T>
inline
void
- count_<T>::set_value(std::size_t c)
+ volume_<T>::set_value(std::size_t c)
{
- count__ = c;
+ volume__ = c;
+ // FIXME: What about area__ and height__ ?
}
# endif // ! MLN_INCLUDE_ONLY
@@ -140,4 +161,4 @@
} // end of namespace mln
-#endif // ! MLN_ACCU_COUNT_HH
+#endif // ! MLN_ACCU_VOLUME_HH
Index: mln/morpho/closing_volume.hh
--- mln/morpho/closing_volume.hh (revision 1987)
+++ mln/morpho/closing_volume.hh (working copy)
@@ -25,16 +25,14 @@
// 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_VOLUME_HH
+# define MLN_MORPHO_CLOSING_VOLUME_HH
-/*! \file mln/morpho/closing_area.hh
- *
- * \brief Morphological area closing.
- */
+/// \file mln/morpho/closing_volume.hh
+/// \brief Morphological volume closing.
# include <mln/morpho/closing_attribute.hh>
-# include <mln/accu/count.hh>
+# include <mln/accu/volume.hh>
namespace mln
@@ -43,9 +41,9 @@
namespace morpho
{
- /// Morphological area closing.
+ /// Morphological volume closing.
template <typename I, typename N, typename O>
- void closing_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ void closing_volume(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
@@ -53,13 +51,13 @@
template <typename I, typename N, typename O>
inline
- void closing_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ void closing_volume(const Image<I>& 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;
// FIXME: Change sig of closing_attribute!
- closing_attribute< accu::count_<pix_t> >(input, nbh, lambda, output);
+ closing_attribute< accu::volume_<pix_t> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -69,4 +67,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_CLOSING_AREA_HH
+#endif // ! MLN_MORPHO_CLOSING_VOLUME_HH
Index: mln/morpho/opening_volume.hh
--- mln/morpho/opening_volume.hh (revision 1988)
+++ mln/morpho/opening_volume.hh (working copy)
@@ -25,16 +25,14 @@
// 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_VOLUME_HH
+# define MLN_MORPHO_OPENING_VOLUME_HH
-/*! \file mln/morpho/opening_area.hh
- *
- * \brief Morphological area opening.
- */
+/// \file mln/morpho/opening_volume.hh
+/// \brief Morphological volume opening.
# include <mln/morpho/opening_attribute.hh>
-# include <mln/accu/count.hh>
+# include <mln/accu/volume.hh>
namespace mln
@@ -43,9 +41,9 @@
namespace morpho
{
- /// Morphological area opening.
+ /// Morphological volume opening.
template <typename I, typename N, typename O>
- void opening_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ void opening_volume(const Image<I>& input, const Neighborhood<N>& nbh,
std::size_t lambda, Image<O>& output);
@@ -53,13 +51,13 @@
template <typename I, typename N, typename O>
inline
- void opening_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ void opening_volume(const Image<I>& 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;
// FIXME: Change sig of opening_attribute!
- opening_attribute< accu::count_<pix_t> >(input, nbh, lambda, output);
+ opening_attribute< accu::volume_<pix_t> >(input, nbh, lambda, output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -69,4 +67,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_OPENING_AREA_HH
+#endif // ! MLN_MORPHO_OPENING_VOLUME_HH
Index: mln/morpho/closing_attribute.hh
--- mln/morpho/closing_attribute.hh (revision 1988)
+++ mln/morpho/closing_attribute.hh (working copy)
@@ -28,10 +28,8 @@
#ifndef MLN_MORPHO_CLOSING_ATTRIBUTE_HH
# define MLN_MORPHO_CLOSING_ATTRIBUTE_HH
-/*! \file mln/morpho/closing_attribute.hh
- *
- * \brief Morphological attribute closing.
- */
+/// \file mln/morpho/closing_attribute.hh
+/// \brief Morphological attribute closing.
# include <mln/morpho/includes.hh>
# include <mln/canvas/morpho/algebraic_union_find.hh>
@@ -83,6 +81,11 @@
void init()
{
// FIXME: border::fill(input, mln_max(mln_value(I)));
+ /* FIXME: Shouldn't it be
+
+ border::fill(input, mln_max(mln_value(I)))
+
+ instead? */
}
inline
Index: mln/morpho/opening_attribute.hh
--- mln/morpho/opening_attribute.hh (revision 1988)
+++ mln/morpho/opening_attribute.hh (working copy)
@@ -28,10 +28,8 @@
#ifndef MLN_MORPHO_OPENING_ATTRIBUTE_HH
# define MLN_MORPHO_OPENING_ATTRIBUTE_HH
-/*! \file mln/morpho/opening_attribute.hh
- *
- * \brief Morphological attribute opening.
- */
+/// \file mln/morpho/opening_attribute.hh
+/// \brief Morphological attribute opening.
# include <mln/morpho/includes.hh>
# include <mln/canvas/morpho/algebraic_union_find.hh>
Index: tests/morpho/closing_volume.cc
--- tests/morpho/closing_volume.cc (revision 1988)
+++ tests/morpho/closing_volume.cc (working copy)
@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/morpho/closing_area.cc
- *
- * \brief Test on mln::morpho::closing_area.
- */
+/// \file tests/morpho/closing_volume.cc
+/// \brief Test on mln::morpho::closing_volume.
#include <mln/core/image2d.hh>
#include <mln/value/int_u8.hh>
@@ -37,12 +35,10 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/closing_volume.hh>
#include "tests/data.hh"
-
-
int main()
{
using namespace mln;
@@ -52,6 +48,6 @@
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
image2d<int_u8> out(lena.domain());
- morpho::closing_area(lena, c4(), 510, out);
+ morpho::closing_volume(lena, c4(), 10000, out);
io::pgm::save(out, "out.pgm");
}
Index: tests/morpho/opening_volume.cc
--- tests/morpho/opening_volume.cc (revision 1988)
+++ tests/morpho/opening_volume.cc (working copy)
@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/morpho/opening_area.cc
- *
- * \brief Test on mln::morpho::opening_area.
- */
+/// \file tests/morpho/opening_volume.cc
+/// \brief Test on mln::morpho::opening_volume.
#include <mln/core/image2d.hh>
#include <mln/value/int_u8.hh>
@@ -37,12 +35,10 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/morpho/opening_area.hh>
+#include <mln/morpho/opening_volume.hh>
#include "tests/data.hh"
-
-
int main()
{
using namespace mln;
@@ -52,6 +48,6 @@
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
image2d<int_u8> out(lena.domain());
- morpho::opening_area(lena, c4(), 510, out);
+ morpho::opening_volume(lena, c4(), 10000, out);
io::pgm::save(out, "out.pgm");
}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1988)
+++ tests/morpho/Makefile.am (working copy)
@@ -5,6 +5,7 @@
check_PROGRAMS = \
artificial_line_graph_image_wst \
closing_area \
+ closing_volume \
combined \
contrast \
dilation \
@@ -19,6 +20,7 @@
meyer_wst \
meyer_wst_long \
opening_area \
+ opening_volume \
thinning
# -------------- #
@@ -34,6 +36,9 @@
opening_area_SOURCES = opening_area.cc
closing_area_SOURCES = closing_area.cc
+closing_volume_SOURCES = closing_volume.cc
+opening_volume_SOURCES = opening_volume.cc
+
contrast_SOURCES = contrast.cc
gradient_SOURCES = gradient.cc
hit_or_miss_SOURCES = hit_or_miss.cc
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Misc. morpho-related fixes.
* mln/morpho/line_gradient.hh
(mln::morpho::line_gradient) [!NDEBUG]: Avoid a warning in debug
mode.
* mln/morpho/meyer_wst.hh: s/markers/output/.
* mln/level/sort_psites.hh: Remove outdated FIXME.
* mln/convert/to_p_array.hh
(mln::convert::to_p_array(const Point_Set<S>&)): Add a FIXME.
* tests/morpho/lena_line_graph_image_wst2.cc: Encode the number of
regions on an `unsigned' value.
Don't re-quantize the watershed result to 8 bits before processing
it, as it could merge bassins.
mln/convert/to_p_array.hh | 7 +++----
mln/level/sort_psites.hh | 14 ++++----------
mln/morpho/line_gradient.hh | 10 +++++++++-
mln/morpho/meyer_wst.hh | 20 ++++++++++----------
tests/morpho/lena_line_graph_image_wst2.cc | 18 +++++-------------
5 files changed, 31 insertions(+), 38 deletions(-)
Index: mln/morpho/line_gradient.hh
--- mln/morpho/line_gradient.hh (revision 1987)
+++ mln/morpho/line_gradient.hh (working copy)
@@ -34,6 +34,8 @@
# include <map>
# include <vector>
+# include <mln/math/abs.hh>
+
# include <mln/core/image2d.hh>
# include <mln/core/window2d.hh>
# include <mln/core/line_graph_image.hh>
@@ -94,10 +96,16 @@
for_all (q)
if (ima.has(q))
{
+ // Avoid a warning about an undefined variable when the
+ // NDEBUG is not defined.
+#ifdef NDEBUG
+ g.add_edge(points[p], points[q]);
+#else // !NDEBUG
util::edge_id id = g.add_edge(points[p], points[q]);
+#endif //!NDEBUG
// The computed value is a norm of the gradient between P and Q.
edge_values.push_back(math::abs(ima(p) - ima(q)));
- assert(id != mln_max(util::edge_id));
+ mln_assertion(id != mln_max(util::edge_id));
}
// Line graph point set.
Index: mln/morpho/meyer_wst.hh
--- mln/morpho/meyer_wst.hh (revision 1987)
+++ mln/morpho/meyer_wst.hh (working copy)
@@ -113,7 +113,7 @@
const marker unmarked = mln_min(marker);
// Initialize the output with the markers (minima components).
- mln_ch_value(I, marker) markers =
+ mln_ch_value(I, marker) output =
labeling::regional_minima (input, nbh, nbasins);
typedef mln_psite(I) psite;
@@ -130,12 +130,12 @@
// Insert every neighbor P of every marked area in a
// hierarchical queue, with a priority level corresponding to
// the grey level input(P).
- mln_piter(I) p(markers.domain());
+ mln_piter(I) p(output.domain());
mln_niter(N) n(nbh, p);
for_all (p)
- if (markers(p) == unmarked)
+ if (output(p) == unmarked)
for_all(n)
- if (markers.has(n) && markers(n) != unmarked)
+ if (output.has(n) && output(n) != unmarked)
{
queue.push(p);
break;
@@ -154,14 +154,14 @@
bool single_adjacent_marker_p = true;
mln_niter(N) n(nbh, p);
for_all(n)
- if (markers.has(n) && markers(n) != unmarked)
+ if (output.has(n) && output(n) != unmarked)
if (adjacent_marker == unmarked)
{
- adjacent_marker = markers(n);
+ adjacent_marker = output(n);
single_adjacent_marker_p = true;
}
else
- if (adjacent_marker != markers(n))
+ if (adjacent_marker != output(n))
{
single_adjacent_marker_p = false;
break;
@@ -172,13 +172,13 @@
hierarchical queue. */
if (single_adjacent_marker_p)
{
- markers(p) = adjacent_marker;
+ output(p) = adjacent_marker;
for_all(n)
- if (markers.has(n) && markers(n) == unmarked)
+ if (output.has(n) && output(n) == unmarked)
queue.push(n);
}
}
- return markers;
+ return output;
}
template <typename L, typename I, typename N>
Index: mln/level/sort_psites.hh
--- mln/level/sort_psites.hh (revision 1987)
+++ mln/level/sort_psites.hh (working copy)
@@ -28,16 +28,10 @@
#ifndef MLN_LEVEL_SORT_PSITES_HH
# define MLN_LEVEL_SORT_PSITES_HH
-/*! \file mln/level/sort_psites.hh
- *
- * \brief Sort_Psites the contents of an image into another one.
- *
- * \todo Factor code + optimize.
- */
-
-/* FIXME: Factor with mln/level/sort_points.hh, if needed (maybe wait
- for the upcoming big changes regarding types associated to images
- (point -> site, etc.). */
+/// \file mln/level/sort_psites.hh
+/// \brief Sort_Psites the contents of an image into another one.
+///
+/// \todo Factor code + optimize.
# include <algorithm>
Index: mln/convert/to_p_array.hh
--- mln/convert/to_p_array.hh (revision 1987)
+++ mln/convert/to_p_array.hh (working copy)
@@ -28,10 +28,8 @@
#ifndef MLN_CONVERT_TO_P_ARRAY_HH
# define MLN_CONVERT_TO_P_ARRAY_HH
-/*! \file mln/convert/to_p_array.hh
- *
- * \brief Conversions to mln::p_array.
- */
+/// \file mln/convert/to_p_array.hh
+/// \brief Conversions to mln::p_array.
# include <mln/core/p_array.hh>
# include <mln/core/concept/window.hh>
@@ -65,6 +63,7 @@
const S& pset = exact(pset_);
p_array<mln_psite(S)> v;
v.reserve(pset.npoints());
+ // FIXME: Why mln_fwd_piter and not mln_piter?
mln_fwd_piter(S) p(pset);
for_all(p)
v.append(p);
Index: tests/morpho/lena_line_graph_image_wst2.cc
--- tests/morpho/lena_line_graph_image_wst2.cc (revision 1987)
+++ tests/morpho/lena_line_graph_image_wst2.cc (working copy)
@@ -44,8 +44,7 @@
\li reduce the number of minima using an area opening (counting the
vertices to compute the area, 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
+ \li create a 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;
\li print the watershed on lines into that same image, and save it. */
@@ -120,18 +119,11 @@
`------*/
// Perform a Watershed Transform.
- typedef int_u16 wst_full_val_t;
- wst_full_val_t nbasins;
- typedef line_graph_image<point2d, wst_full_val_t> wst_full_ima_t;
- wst_full_ima_t wshed_full = morpho::meyer_wst(closed_lg_ima, nbh, nbasins);
- std::cout << "nbasins = " << nbasins << std::endl;
-
- // Reduce the value set to 8-bit.
- typedef int_u8 wst_val_t;
+ typedef unsigned wst_val_t;
+ wst_val_t nbasins;
typedef line_graph_image<point2d, wst_val_t> wst_ima_t;
- wst_ima_t wshed;
- initialize(wshed, wshed_full);
- level::stretch(wshed_full, wshed);
+ wst_ima_t wshed = morpho::meyer_wst(closed_lg_ima, nbh, nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
/*---------.
| Output. |
1
0