* mln/labeling/all.hh: include new header.
* mln/labeling/relabel.hh: move an overload...
* mln/labeling/pack.hh: ... in this new routine.
* tests/labeling/Makefile.am,
* tests/labeling/pack.cc: add a new test.
---
milena/ChangeLog | 14 ++-
milena/mln/labeling/all.hh | 1 +
milena/mln/labeling/pack.hh | 151 ++++++++++++++++++++
milena/mln/labeling/relabel.hh | 78 ++---------
milena/tests/labeling/Makefile.am | 2 +
.../labeling/all.hh => tests/labeling/pack.cc} | 68 +++++-----
6 files changed, 214 insertions(+), 100 deletions(-)
create mode 100644 milena/mln/labeling/pack.hh
copy milena/{mln/labeling/all.hh => tests/labeling/pack.cc} (56%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 76e2c32..a52c977 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,4 +1,16 @@
-2009-04-08 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+2009-04-09 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add labeling::pack.
+
+ * mln/labeling/all.hh: include new header.
+
+ * mln/labeling/relabel.hh: move an overload...
+ * mln/labeling/pack.hh: ... in this new routine.
+
+ * tests/labeling/Makefile.am,
+ * tests/labeling/pack.cc: add a new test.
+
+2009-04-09 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
Small fixes.
diff --git a/milena/mln/labeling/all.hh b/milena/mln/labeling/all.hh
index 798ee02..2931427 100644
--- a/milena/mln/labeling/all.hh
+++ b/milena/mln/labeling/all.hh
@@ -61,6 +61,7 @@ namespace mln
# include <mln/labeling/foreground.hh>
# include <mln/labeling/level.hh>
# include <mln/labeling/n_max.hh>
+# include <mln/labeling/pack.hh>
# include <mln/labeling/regional_maxima.hh>
# include <mln/labeling/regional_minima.hh>
diff --git a/milena/mln/labeling/pack.hh b/milena/mln/labeling/pack.hh
new file mode 100644
index 0000000..45a08e3
--- /dev/null
+++ b/milena/mln/labeling/pack.hh
@@ -0,0 +1,151 @@
+// Copyright (C) 2009 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_LABELING_PACK_HH
+# define MLN_LABELING_PACK_HH
+
+/// \file mln/labeling/pack.hh
+///
+/// Remove components and relabel a labeled image in order to have a
+/// contiguous labeling.
+
+
+# include <mln/core/concept/image.hh>
+
+# include <mln/make/relabelfun.hh>
+
+# include <mln/level/compute.hh>
+# include <mln/level/transform.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)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels);
+
+
+
+ /// 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);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I>
+ void
+ pack_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;
+ }
+
+ } // end of mln::labeling::internal
+
+
+
+ template <typename I>
+ mln_concrete(I)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::pack");
+
+ internal::pack_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::pack");
+ return output;
+ }
+
+
+
+ template <typename I>
+ void
+ pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::pack_inplace");
+
+ internal::pack_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::pack_inplace");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_PACK_HH
diff --git a/milena/mln/labeling/relabel.hh b/milena/mln/labeling/relabel.hh
index c24c0dd..e811db1 100644
--- a/milena/mln/labeling/relabel.hh
+++ b/milena/mln/labeling/relabel.hh
@@ -33,28 +33,23 @@
///
/// Remove components and relabel a labeled image.
+
# 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.
@@ -64,6 +59,7 @@ namespace mln
/// by the background.
///
/// \return the relabeled image.
+ //
template <typename I, typename F>
mln_concrete(I)
relabel(const Image<I>& label,
@@ -71,6 +67,7 @@ namespace mln
mln_value(I)& new_nlabels,
const Function_v2b<F>& fv2b);
+
/// Remove components and relabel a labeled image.
/// \input[in] label the labeled image.
/// \input[in] nlabels the number of labels in \p label.
@@ -78,39 +75,33 @@ namespace mln
/// value.
///
/// \return the relabeled image.
+ //
template <typename I, typename F>
mln_concrete(I)
relabel(const Image<I>& label,
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.
/// \input[in] f function returning whether a label must be replaced
/// by the background.
- ///
+ //
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const Function_v2b<F>& fv2b);
+
/// 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.
/// \input[in] f function returning the new component id for each
/// pixel value.
- ///
+ //
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
@@ -185,29 +176,6 @@ 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
@@ -249,28 +217,6 @@ 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
void
diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am
index f436f63..411674e 100644
--- a/milena/tests/labeling/Makefile.am
+++ b/milena/tests/labeling/Makefile.am
@@ -12,6 +12,7 @@ check_PROGRAMS = \
level \
mean_values \
n_max \
+ pack \
regional_maxima \
regional_minima \
relabel \
@@ -26,6 +27,7 @@ foreground_SOURCES = foreground.cc
level_SOURCES = level.cc
mean_values_SOURCES = mean_values.cc
n_max_SOURCES = n_max.cc
+pack_SOURCES = pack.cc
regional_maxima_SOURCES = regional_maxima.cc
regional_minima_SOURCES = regional_minima.cc
relabel_SOURCES = relabel.cc
diff --git a/milena/mln/labeling/all.hh b/milena/tests/labeling/pack.cc
similarity index 56%
copy from milena/mln/labeling/all.hh
copy to milena/tests/labeling/pack.cc
index 798ee02..b839d64 100644
--- a/milena/mln/labeling/all.hh
+++ b/milena/tests/labeling/pack.cc
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2009 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
@@ -26,43 +26,45 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LABELING_ALL_HH
-# define MLN_LABELING_ALL_HH
-
-/// \file mln/labeling/all.hh
-///
-/// File that includes all labeling routines.
+/// \file tests/labeling/pack.cc
///
-/// \todo Many files in this directory have to be updated with the
-/// test and dispatch mechanisms.
+/// Tests on mln::labeling::pack.
-namespace mln
-{
+#include <mln/core/image/image2d.hh>
+#include <mln/labeling/pack.hh>
+#include <mln/level/compare.hh>
+#include <mln/value/label_16.hh>
+#include <mln/debug/println.hh>
- /// Namespace of labeling routines.
- namespace labeling
- {
- /// Implementation namespace of labeling namespace.
- namespace impl {
+int main()
+{
+ using namespace mln;
+ using value::label_16;
- /// Generic implementation namespace of labeling namespace.
- namespace generic {}
+ label_16 vals2[6][5] = {
+ { 0, 10, 10, 0, 0},
+ { 0, 10, 10, 4, 0},
+ { 0, 0, 0, 0, 0},
+ {12, 12, 0, 3, 0},
+ {12, 50, 3, 3, 3},
+ {12, 50, 50, 0, 0}
+ };
- }
- }
-}
+ label_16 vals_ref[6][5] = {
+ { 0, 3, 3, 0, 0},
+ { 0, 3, 3, 2, 0},
+ { 0, 0, 0, 0, 0},
+ { 4, 4, 0, 1, 0},
+ { 4, 5, 1, 1, 1},
+ { 4, 5, 5, 0, 0}
+ };
-# include <mln/labeling/background.hh>
-# include <mln/labeling/blobs.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/labeling/fill_holes.hh>
-# include <mln/labeling/flat_zones.hh>
-# include <mln/labeling/foreground.hh>
-# include <mln/labeling/level.hh>
-# include <mln/labeling/n_max.hh>
-# include <mln/labeling/regional_maxima.hh>
-# include <mln/labeling/regional_minima.hh>
+ image2d<label_16> lbl2 = make::image(vals2);
+ image2d<label_16> lbl_ref = make::image(vals_ref);
+ label_16 nlabels;
+ image2d<label_16> relbl = labeling::pack(lbl2, nlabels);
-#endif // ! MLN_LABELING_ALL_HH
+ mln_assertion(lbl_ref == relbl);
+}
--
1.5.6.5