* mln/convert/from_to.hxx,
* mln/value/label.hh: add conversion from int_u<n> to label<m>.
* mln/fun/x2x/rotation.hh,
* mln/fun/x2x/translation.hh: update doc.
* mln/labeling/relabel.hh: add a new overload.
* mln/labeling/wrap.hh: add a new overload with a default argument.
* mln/util/couple.hh: make it a class.
---
milena/ChangeLog | 16 ++++++++
milena/mln/convert/from_to.hxx | 5 ++
milena/mln/fun/x2x/rotation.hh | 2 +-
milena/mln/fun/x2x/translation.hh | 13 ++----
milena/mln/labeling/relabel.hh | 76 +++++++++++++++++++++++++++++++++++++
milena/mln/labeling/wrap.hh | 20 ++++++++++
milena/mln/util/couple.hh | 3 +-
milena/mln/value/label.hh | 16 ++++++++
8 files changed, 140 insertions(+), 11 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c7c171e..e173b6b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,21 @@
2009-04-07 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Small fixes.
+
+ * mln/convert/from_to.hxx,
+ * mln/value/label.hh: add conversion from int_u<n> to label<m>.
+
+ * mln/fun/x2x/rotation.hh,
+ * mln/fun/x2x/translation.hh: update doc.
+
+ * mln/labeling/relabel.hh: add a new overload.
+
+ * mln/labeling/wrap.hh: add a new overload with a default argument.
+
+ * mln/util/couple.hh: make it a class.
+
+2009-04-07 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add new accumulators related to labels.
* mln/accu/all.hh: include new accumulators.
diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx
index eb05b13..d21304c 100644
--- a/milena/mln/convert/from_to.hxx
+++ b/milena/mln/convert/from_to.hxx
@@ -175,6 +175,11 @@ namespace mln
template <unsigned n>
void from_to_(const value::int_u<n>& from, value::label<n>&
to_);
+ // int_u<n> -> label<m> with n < m
+ template <unsigned n, unsigned m>
+ void
+ from_to_(const value::int_u<n>& from, value::label<m>& to_);
+
// hsl -> rgb8.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to);
diff --git a/milena/mln/fun/x2x/rotation.hh b/milena/mln/fun/x2x/rotation.hh
index cbe1dd2..b38cffb 100644
--- a/milena/mln/fun/x2x/rotation.hh
+++ b/milena/mln/fun/x2x/rotation.hh
@@ -148,7 +148,7 @@ namespace mln
/// Constructor without argument.
rotation();
- /// Constructor with grade alpha and a facultative direction (rotation axis).
+ /// Constructor with radian alpha and a facultative direction (rotation axis).
rotation(float alpha, const algebra::vec<n,float>& axis);
/// Constructor with quaternion
rotation(const algebra::quat& q);
diff --git a/milena/mln/fun/x2x/translation.hh b/milena/mln/fun/x2x/translation.hh
index 4101d77..a6e8a39 100644
--- a/milena/mln/fun/x2x/translation.hh
+++ b/milena/mln/fun/x2x/translation.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +28,9 @@
#ifndef MLN_FUN_X2X_TRANSLATION_HH
# define MLN_FUN_X2X_TRANSLATION_HH
-/*! \file mln/fun/x2x/translation.hh
- *
- * \brief Define a translation function.
- */
+/// \file mln/fun/x2x/translation.hh
+///
+/// Define a translation function.
# include <mln/core/concept/function.hh>
# include <mln/fun/internal/x2x_linear_impl.hh>
@@ -48,9 +47,7 @@ namespace mln
namespace x2x
{
- /*! \brief Represent a translation function.
- *
- */
+ /// Represent a translation function.
template <unsigned n, typename C>
struct translation
: fun::internal::x2x_linear_impl_< algebra::vec<n,C>,
translation<n,C> >
diff --git a/milena/mln/labeling/relabel.hh b/milena/mln/labeling/relabel.hh
index 47ca647..c24c0dd 100644
--- a/milena/mln/labeling/relabel.hh
+++ b/milena/mln/labeling/relabel.hh
@@ -35,15 +35,26 @@
# include <mln/core/concept/image.hh>
# include <mln/make/relabelfun.hh>
+# include <mln/level/compute.hh>
# include <mln/level/transform.hh>
# include <mln/level/transform_inplace.hh>
# include <mln/value/label.hh>
+# include <mln/accu/label_used.hh>
namespace mln
{
namespace labeling
{
+ /// Relabel a labeled image in order to have a contiguous labeling.
+ /// \input[in] label The labeled image.
+ /// \input[out] new_nlabels The number of labels after relabeling.
+ ///
+ /// \return The relabeled image.
+ template <typename I>
+ mln_concrete(I)
+ relabel(const Image<I>& label,
+ mln_value(I)& new_nlabels);
/// Remove components and relabel a labeled image.
/// \input[in] label the labeled image.
@@ -73,6 +84,15 @@ namespace mln
const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v);
+ /// Relabel inplace a labeled image in order to have a contiguous
+ /// labeling.
+ /// \input[in] label The labeled image.
+ /// \input[out] new_nlabels The number of labels after relabeling.
+ template <typename I>
+ void
+ relabel_inplace(Image<I>& label,
+ mln_value(I)& new_nlabels);
+
/// Remove components and relabel a labeled image inplace.
/// \input[in, out] label the labeled image.
/// \input[in, out] nlabels the number of labels in \p label.
@@ -105,6 +125,18 @@ namespace mln
namespace internal
{
+ template <typename I>
+ void
+ relabel_tests(const Image<I>& label,
+ mln_value(I)& new_nlabels)
+ {
+ // FIXME: we may want to check that it is exactly a label.
+ mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
+ mln_precondition(exact(label).is_valid());
+ (void) label;
+ (void) new_nlabels;
+ }
+
template <typename I, typename F>
void
relabel_tests(const Image<I>& label,
@@ -153,6 +185,29 @@ namespace mln
} // end of namespace mln::labeling::internal
+ template <typename I>
+ mln_concrete(I)
+ relabel(const Image<I>& label,
+ mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::relabel");
+
+ internal::relabel_tests(label, new_nlabels);
+
+ fun::i2v::array<bool>
+ fv2b = level::compute(accu::meta::label_used(), label);
+
+ mln_value(I) tmp_nlabels = fv2b.size() - 1;
+ mln_concrete(I)
+ output = level::transform(label,
+ make::relabelfun(fv2b,
+ tmp_nlabels,
+ new_nlabels));
+
+ trace::exiting("labeling::relabel");
+ return output;
+ }
+
template <typename I, typename F>
inline
@@ -194,6 +249,27 @@ namespace mln
}
+ template <typename I>
+ void
+ relabel_inplace(Image<I>& label,
+ mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::relabel_inplace");
+
+ internal::relabel_tests(label, new_nlabels);
+
+ fun::i2v::array<bool>
+ fv2b = level::compute(accu::meta::label_used(), label);
+
+ mln_value(I) tmp_nlabels = fv2b.size() - 1;
+ exact(label) = level::transform(label,
+ make::relabelfun(fv2b,
+ tmp_nlabels,
+ new_nlabels));
+
+ trace::exiting("labeling::relabel_inplace");
+ }
+
template <typename I, typename F>
inline
diff --git a/milena/mln/labeling/wrap.hh b/milena/mln/labeling/wrap.hh
index aa6478f..5a29870 100644
--- a/milena/mln/labeling/wrap.hh
+++ b/milena/mln/labeling/wrap.hh
@@ -39,6 +39,7 @@
# include <mln/fun/l2l/wrap.hh>
# include <mln/metal/converts_to.hh>
# include <mln/metal/is_a.hh>
+# include <mln/value/label_8.hh>
namespace mln
{
@@ -57,6 +58,15 @@ namespace mln
mln_ch_value(I,V)
wrap(const V& value_type, const Image<I>& input);
+ /// Wrap labels such as 0 -> 0 and [1, lmax] maps to [1,
+ /// Lmax] (using modulus). Use label_8 as label type.
+ ///
+ /// \param[in] input The label image.
+ ///
+ /// \return A new image with values wrapped with type label_8.
+ template <typename I>
+ mln_ch_value(I,value::label_8)
+ wrap(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
@@ -70,6 +80,7 @@ namespace mln
// mlc_is_a(mln_value(I), value::Symbolic)::check();
mln_precondition(exact(input).is_valid());
+ (void) value_type;
mln_ch_value(I,V) output = level::transform(input, fun::l2l::wrap<V>());
@@ -77,6 +88,15 @@ namespace mln
return output;
}
+
+ template <typename I>
+ inline
+ mln_ch_value(I,value::label_8)
+ wrap(const Image<I>& input)
+ {
+ return wrap(value::label_8(), input);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::labeling
diff --git a/milena/mln/util/couple.hh b/milena/mln/util/couple.hh
index 00b69d4..5f43c27 100644
--- a/milena/mln/util/couple.hh
+++ b/milena/mln/util/couple.hh
@@ -45,13 +45,12 @@ namespace mln
{
template <typename T, typename U>
- struct couple : public mln::Object< couple<T,U> >
+ class couple : public mln::Object< couple<T,U> >
{
public:
couple();
couple(const T& val1, const U& val2);
- public:
/// Get the first member of the couple.
/// \{
const T& first() const;
diff --git a/milena/mln/value/label.hh b/milena/mln/value/label.hh
index a48afeb..054524a 100644
--- a/milena/mln/value/label.hh
+++ b/milena/mln/value/label.hh
@@ -103,6 +103,11 @@ namespace mln
void
from_to_(const value::int_u<n>& from, value::label<n>& to_);
+ // int_u -> label.
+ template <unsigned n, unsigned m>
+ void
+ from_to_(const value::int_u<n>& from, value::label<m>& to_);
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
@@ -197,6 +202,17 @@ namespace mln
to_ = from;
}
+ // int_u<n> -> label<m> with n < m.
+ template <unsigned n, unsigned m>
+ inline
+ void
+ from_to_(const value::int_u<n>& from, value::label<m>& to_)
+ {
+ enum { valid = n < m };
+ metal::bool_<valid>::check();
+ to_ = from;
+ }
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
--
1.5.6.5