cleanup-2008 2800: Update level stretch so that output is returned.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update level stretch so that output is returned. * mln/level/stretch.hh: Change sig to return output. * tests/level/stretch.cc: Update. * tests/level/stretch_full.cc: Update. * tests/linear/lap.cc: Update. * tests/linear/log.cc: Update. mln/level/stretch.hh | 72 ++++++++++++++++++++++++++++---------------- tests/level/stretch.cc | 19 ++++------- tests/level/stretch_full.cc | 27 +++++----------- tests/linear/lap.cc | 14 ++++---- tests/linear/log.cc | 9 ++--- 5 files changed, 74 insertions(+), 67 deletions(-) Index: tests/level/stretch_full.cc --- tests/level/stretch_full.cc (revision 2799) +++ tests/level/stretch_full.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -25,25 +26,22 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/level/stretch_full.cc - * - * \brief Tests on mln::level::stretch. - */ - +/// \file tests/level/stretch_full.cc +/// +/// Tests on mln::level::stretch. +/// +/// \todo Make it pass. #include <mln/core/image/image1d.hh> #include <mln/core/image/image2d.hh> #include <mln/core/image/image3d.hh> #include <mln/value/int_u8.hh> -#include <mln/value/int_u16.hh> - #include <mln/value/int_s8.hh> +#include <mln/value/int_u16.hh> #include <mln/value/int_s16.hh> - #include <mln/debug/iota.hh> - #include <mln/level/saturate.hh> #include <mln/level/stretch.hh> @@ -55,16 +53,9 @@ void chck(Image<I>& input_, Image<J>& output_) { - typedef mln_value(I) T; - typedef mln_value(J) V; - unsigned max_i = mln_max (T); - unsigned max_j = mln_max (V); I& input = exact(input_); J& output = exact(output_); - - level::stretch(input, output); - - // FIXME: How to test that? + output = level::stretch(mln_value(J)(), input); } template <typename I, typename J> Index: tests/level/stretch.cc --- tests/level/stretch.cc (revision 2799) +++ tests/level/stretch.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -25,11 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/level/stretch.cc - * - * \brief Tests on mln::level::stretch. - */ - +/// \file tests/level/stretch.cc +/// +/// Tests on mln::level::stretch. #include <mln/core/image/image2d.hh> #include <mln/level/stretch.hh> @@ -47,18 +46,16 @@ { 1000, 2000, 3000 }, { 1000, 2000, 3000 } }; - image2d<int> ima(make::image(vs)); - - image2d<int_u8> out(3, 3); + image2d<int> ima = make::image(vs); + image2d<int_u8> out = level::stretch(int_u8(), ima); int_u8 ws[3][3] = { { 0, 127, 255 }, { 0, 127, 255 }, { 0, 127, 255 } }; + image2d<int_u8> ref = make::image(ws); - image2d<int_u8> ref(make::image(ws)); - level::stretch(ima, out); box_fwd_piter_<point2d> p(out.domain()); for_all(p) mln_assertion(out(p) == ref(p)); Index: tests/linear/lap.cc --- tests/linear/lap.cc (revision 2799) +++ tests/linear/lap.cc (working copy) @@ -26,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/linear/lap.cc - * - * \brief Tests on mln::linear::lap_4. - */ +/// \file tests/linear/lap.cc +/// +/// Tests on mln::linear::lap_4. #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> @@ -50,8 +49,9 @@ border::thickness = 1; - image2d<int_u8> lena, out; + image2d<int_u8> lena; io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); - level::stretch(linear::lap_4(lena), out); - io::pgm::save(out, "out.pgm"); + + io::pgm::save(level::stretch(int_u8(), linear::lap_4(lena)), + "out.pgm"); } Index: tests/linear/log.cc --- tests/linear/log.cc (revision 2799) +++ tests/linear/log.cc (working copy) @@ -26,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/linear/log.cc - * - * \brief Tests on mln::linear. - */ +/// \file tests/linear/log.cc +/// +/// Tests on mln::linear. #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> @@ -63,7 +62,7 @@ mln_assertion(min == -929 && max == 1260); } - level::stretch(tmp, out); + out = level::stretch(int_u8(), tmp); io::pgm::save(out, "out.pgm"); { int_u8 min, max; Index: mln/level/stretch.hh --- mln/level/stretch.hh (revision 2799) +++ mln/level/stretch.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,11 +29,14 @@ #ifndef MLN_LEVEL_STRETCH_HH # define MLN_LEVEL_STRETCH_HH -/*! \file mln/level/stretch.hh - * - * \brief Transform with fun::stretch the contents of an image into - * another one. - */ +/// \file mln/level/stretch.hh +/// +/// Transform linearly the contents of an image into another one in a +/// stretching way. +/// +/// \todo Make it work with other types than scalars (e.g., vectors). +/// +/// \todo Think about adding a stretch_inplace(?) # include <mln/estim/min_max.hh> # include <mln/value/int_u.hh> @@ -46,15 +50,18 @@ namespace level { - /*! Stretch the values of \p input so that they can be stored in \p output. + /*! Stretch the values of \p input so that they can be stored in + * \p output. * + * \param[in] v A value to set the output value type. * \param[in] input The input image. * \param[out] output The result image. * - * \pre \p output.domain == \p input.domain + * \pre input.has_data */ - template <typename I, typename O> - void stretch(const Image<I>& input, Image<O>& output); + template <typename V, typename I> + mln_ch_value(I, V) + stretch(V v, const Image<I>& input); # ifndef MLN_INCLUDE_ONLY @@ -62,45 +69,58 @@ namespace impl { - // FIXME: The first argument seems to have no effect. - template <unsigned n, typename I, typename O> + template <typename V, typename I> inline - void stretch(value::int_u<n>, - const Image<I>& input, Image<O>& output) + mln_ch_value(I, V) + stretch(V, const Image<I>& input) { trace::entering("level::impl::stretch"); + mlc_converts_to(float, V)::check(); + + mln_ch_value(I, V) output; + mln_value(I) min_, max_; estim::min_max(input, min_, max_); if (max_ != min_) { - float min = float(min_), max = float(max_); - const float epsilon = mln_epsilon(float); - float m = 0.0f - 0.5f + epsilon; - float M = mln_max(value::int_u<n>) + 0.5f - epsilon; - float a = (M - m) / (max - min); - float b = (m * max - M * min) / (max - min); - fun::v2v::linear<float, float, int> f(a, b); + float + min = float(min_), + max = float(max_), + epsilon = mln_epsilon(float), + m = 0.0f - 0.5f + epsilon, + M = mln_max(V) + 0.5f - epsilon, + a = (M - m) / (max - min), + b = (m * max - M * min) / (max - min); + fun::v2v::linear<float, float, V> f(a, b); output = level::transform(input, f); } + else + { + initialize(output, input); + // trace::warning("output has no significative data!"); + } + trace::exiting("level::impl::stretch"); + return output; } } // end of namespace mln::level::impl - template <typename I, typename O> + template <typename V, typename I> inline - void stretch(const Image<I>& input, Image<O>& output) + mln_ch_value(I, V) + stretch(V, const Image<I>& input) { trace::entering("level::stretch"); - initialize(output, input); + mln_precondition(exact(input).has_data()); - mln_precondition(exact(output).domain() == exact(input).domain()); - impl::stretch(mln_value(O)(), input, output); + mln_ch_value(I, V) output = impl::stretch(V(), input); trace::exiting("level::stretch"); + return output; } # endif // ! MLN_INCLUDE_ONLY
participants (1)
-
Thierry Geraud