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