
* mln/labeling/mean_values.hh: add a more generic version. * tests/labeling/Makefile.am, * tests/labeling/mean_values.cc: add missing test. --- milena/ChangeLog | 9 ++++ milena/mln/labeling/mean_values.hh | 52 ++++++++++++++++++------- milena/tests/labeling/Makefile.am | 2 + milena/tests/labeling/mean_values.cc | 70 ++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 milena/tests/labeling/mean_values.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 53827ae..62d0de4 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,14 @@ 2009-02-23 Guillaume Lazzara <z@lrde.epita.fr> + Add a missing test for labeling::mean_values. + + * mln/labeling/mean_values.hh: add a more generic version. + + * tests/labeling/Makefile.am, + * tests/labeling/mean_values.cc: add missing test. + +2009-02-23 Guillaume Lazzara <z@lrde.epita.fr> + Various small fixes. * doc/tutorial/samples/win-create-1.cc: fix ref output. diff --git a/milena/mln/labeling/mean_values.hh b/milena/mln/labeling/mean_values.hh index 7014c59..0565abb 100644 --- a/milena/mln/labeling/mean_values.hh +++ b/milena/mln/labeling/mean_values.hh @@ -28,6 +28,15 @@ #ifndef MLN_LABELING_MEAN_VALUES_HH # define MLN_LABELING_MEAN_VALUES_HH +/// \file mln/labeling/mean_values.hh +/// +/// Construct from a labeled image a new image, the labels values are +/// replaced by the components mean values. +/// +/// \todo handle mean value for label 0 correctly. +/// \todo merge rgb and generic version. + + # include <mln/core/concept/image.hh> # include <mln/core/alias/vec3d.hh> @@ -39,11 +48,6 @@ # include <mln/literal/colors.hh> -/// \file mln/labeling/mean_values.hh -/// -/// Construct from a labeled image a new image, the labels values are -/// replaced by the components mean values. - namespace mln { @@ -92,15 +96,35 @@ namespace mln template <typename I, typename L> mln_concrete(I) - mean_values(const Image<I>& input, - const Image<L>& lbl, mln_value(L) nlabels) + mean_values(const Image<I>& input_, + const Image<L>& lbl_, mln_value(L) nlabels) { - internal::mean_values_tests(input, lbl, nlabels); + trace::entering("mln::labeling::impl::generic::mean_values"); + + internal::mean_values_tests(input_, lbl_, nlabels); + + const I& input = exact(input_); + const L& lbl = exact(lbl_); + typedef mln_value(L) LV; + typedef mln_value(I) IV; + + util::array<float> m_3f + = labeling::compute(accu::mean<IV>(), + input, // input color image + lbl, // watershed labeling + nlabels); + m_3f[0] = 0.f; + + util::array<IV> m; + convert::from_to(m_3f, m); + m[0] = 150u; //FIXME: handle label 0 correctly. + + mln_concrete(I) output = level::transform(lbl, + convert::to< fun::i2v::array<IV> >(m)); + - trace::warning("labeling::impl::generic::mean_values() is not \ - implemented!"); - //FIXME: to write! - abort(); + trace::exiting("mln::labeling::impl::generic::mean_values"); + return output; } } @@ -110,7 +134,7 @@ namespace mln mean_values_rgb(const Image<I>& input_, const Image<L>& lbl_, mln_value(L) nlabels) { - trace::entering("mln::labeling::mean_values_rgb"); + trace::entering("mln::labeling::impl::mean_values_rgb"); internal::mean_values_tests(input_, lbl_, nlabels); @@ -131,7 +155,7 @@ namespace mln convert::to< fun::i2v::array<mln_value(I)> >(m)); - trace::exiting("mln::labeling::mean_values_rgb"); + trace::exiting("mln::labeling::impl::mean_values_rgb"); return output; } diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am index 083244a..6b3231f 100644 --- a/milena/tests/labeling/Makefile.am +++ b/milena/tests/labeling/Makefile.am @@ -10,6 +10,7 @@ check_PROGRAMS = \ flat_zones \ foreground \ level \ + mean_values \ n_max \ regional_maxima \ regional_minima \ @@ -22,6 +23,7 @@ fill_holes_SOURCES = fill_holes.cc flat_zones_SOURCES = flat_zones.cc foreground_SOURCES = foreground.cc level_SOURCES = level.cc +mean_values_SOURCES = mean_values.cc n_max_SOURCES = n_max.cc regional_maxima_SOURCES = regional_maxima.cc regional_minima_SOURCES = regional_minima.cc diff --git a/milena/tests/labeling/mean_values.cc b/milena/tests/labeling/mean_values.cc new file mode 100644 index 0000000..c46193a --- /dev/null +++ b/milena/tests/labeling/mean_values.cc @@ -0,0 +1,70 @@ +// 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/blobs.cc +/// +/// Test on mln::labeling::mean_values. + +#include <mln/core/image/image2d.hh> + +#include <mln/level/compare.hh> + +#include <mln/labeling/mean_values.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/label_8.hh> + +#include "tests/data.hh" + +int main() +{ + using namespace mln; + using value::int_u8; + using value::label_8; + + int_u8 input_[16] = { 1, 2, 0, 1, + 3, 0, 2, 3, + 0, 0, 2, 3, + 1, 1, 0, 1 }; + image2d<int_u8> input = make::image2d(input_); + + label_8 lbl_[16] = { 1, 1, 0, 2, + 1, 0, 2, 2, + 0, 0, 2, 2, + 3, 3, 0, 2 }; + image2d<label_8> lbl = make::image2d(lbl_); + + int_u8 means_[16] = { 2, 2, 150, 2, + 2, 150, 2, 2, + 150, 150, 2, 2, + 1, 1, 150, 2 }; + image2d<int_u8> means = make::image2d(means_); + + image2d<int_u8> res = labeling::mean_values(input, lbl, 3); + + mln_assertion(res == means); +} -- 1.5.6.5