
* mln/labeling/wrap.hh: new routine. * tests/labeling/Makefile.am, * tests/labeling/wrap.cc: new test. --- milena/ChangeLog | 9 ++++ milena/mln/labeling/wrap.hh | 86 +++++++++++++++++++++++++++++++++++++ milena/tests/labeling/Makefile.am | 4 +- milena/tests/labeling/wrap.cc | 64 +++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 1 deletions(-) create mode 100644 milena/mln/labeling/wrap.hh create mode 100644 milena/tests/labeling/wrap.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 7334d37..76e8920 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,14 @@ 2009-04-01 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add labeling::wrap routine. + + * mln/labeling/wrap.hh: new routine. + + * tests/labeling/Makefile.am, + * tests/labeling/wrap.cc: new test. + +2009-04-01 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add a new routine to create a region adjacency graph. * mln/make/rag_and_labeled_wsl.hh: new routine. diff --git a/milena/mln/labeling/wrap.hh b/milena/mln/labeling/wrap.hh new file mode 100644 index 0000000..aa6478f --- /dev/null +++ b/milena/mln/labeling/wrap.hh @@ -0,0 +1,86 @@ +// 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_WRAP_HH +# define MLN_LABELING_WRAP_HH + +/// \file mln/labeling/wrap.hh +/// +/// Wrap labels such as 0 -> 0 and [1, lmax] maps to [1, +/// Lmax] (using modulus). + +# include <mln/core/concept/image.hh> +# include <mln/level/transform.hh> +# include <mln/fun/l2l/wrap.hh> +# include <mln/metal/converts_to.hh> +# include <mln/metal/is_a.hh> + +namespace mln +{ + + namespace labeling + { + + /// Wrap labels such as 0 -> 0 and [1, lmax] maps to [1, + /// Lmax] (using modulus). + /// + /// \param[in] value_type The type used to wrap the label type. + /// \param[in] input The label image. + /// + /// \return A new image with values wrapped with type V. + template <typename V, typename I> + mln_ch_value(I,V) + wrap(const V& value_type, const Image<I>& input); + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename V, typename I> + inline + mln_ch_value(I,V) + wrap(const V& value_type, const Image<I>& input) + { + trace::entering("labeling::wrap"); + +// mlc_is_a(mln_value(I), value::Symbolic)::check(); + mln_precondition(exact(input).is_valid()); + + mln_ch_value(I,V) output = level::transform(input, fun::l2l::wrap<V>()); + + trace::exiting("labeling::wrap"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::labeling + +} // end of namespace mln + +#endif // ! MLN_LABELING_WRAP_HH diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am index 6b3231f..f436f63 100644 --- a/milena/tests/labeling/Makefile.am +++ b/milena/tests/labeling/Makefile.am @@ -14,7 +14,8 @@ check_PROGRAMS = \ n_max \ regional_maxima \ regional_minima \ - relabel + relabel \ + wrap background_SOURCES = background.cc blobs_SOURCES = blobs.cc @@ -28,5 +29,6 @@ n_max_SOURCES = n_max.cc regional_maxima_SOURCES = regional_maxima.cc regional_minima_SOURCES = regional_minima.cc relabel_SOURCES = relabel.cc +wrap_SOURCES = wrap.cc TESTS = $(check_PROGRAMS) diff --git a/milena/tests/labeling/wrap.cc b/milena/tests/labeling/wrap.cc new file mode 100644 index 0000000..b5e8a71 --- /dev/null +++ b/milena/tests/labeling/wrap.cc @@ -0,0 +1,64 @@ +// 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. + +/// \file tests/labeling/wrap.cc +/// +/// Test on mln::labeling::wrap. + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> +#include <mln/make/image2d.hh> +#include <mln/labeling/wrap.hh> +#include <mln/level/compare.hh> + +#include <mln/debug/println.hh> + +#include "tests/data.hh" + + +int main() +{ + using namespace mln; + using value::int_u8; + using value::int_u16; + + int_u16 values[] = { 1, 1000, + 0, 65534 }; + + int_u8 ref_values[] = { 1, 235, + 0, 254 }; + + image2d<int_u16> ima = make::image2d(values); + image2d<int_u8> ima_ref = make::image2d(ref_values); + + image2d<int_u8> ima_wrapped = labeling::wrap(int_u8(), ima); + + mln_assertion(ima_ref == ima_wrapped); +} -- 1.5.6.5