olena: olena-2.0-554-g9a6e78a Add data::stretch_inplace.

* mln/data/stretch.hh: Remove fixme. * mln/data/stretch_inplace.hh, * tests/data/stretch_inplace.cc: New. * tests/data/Makefile.am: New target. --- milena/ChangeLog | 11 +++ milena/mln/data/stretch.hh | 10 ++- milena/mln/data/stretch_inplace.hh | 76 ++++++++++--------- milena/tests/data/Makefile.am | 3 +- .../tests/data/{saturate.cc => stretch_inplace.cc} | 25 ++++--- 5 files changed, 74 insertions(+), 51 deletions(-) copy milena/tests/data/{saturate.cc => stretch_inplace.cc} (76%) diff --git a/milena/ChangeLog b/milena/ChangeLog index edf3a65..27b023e 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,14 @@ +2013-04-29 Guillaume Lazzara <z@lrde.epita.fr> + + Add data::stretch_inplace. + + * mln/data/stretch.hh: Remove fixme. + + * mln/data/stretch_inplace.hh, + * tests/data/stretch_inplace.cc: New. + + * tests/data/Makefile.am: New target. + 2013-04-17 Guillaume Lazzara <z@lrde.epita.fr> * doc/mln/convert.dox: Fix from_to_ module name. diff --git a/milena/mln/data/stretch.hh b/milena/mln/data/stretch.hh index 5b36dbe..2473494 100644 --- a/milena/mln/data/stretch.hh +++ b/milena/mln/data/stretch.hh @@ -33,8 +33,6 @@ /// 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> @@ -82,7 +80,7 @@ namespace mln template <typename V, typename I> inline mln_ch_value(I, V) - stretch(const V& v, const Image<I>& input) + stretch(const V& v, const Image<I>& input) { mln_trace("data::impl::stretch"); @@ -95,6 +93,12 @@ namespace mln estim::min_max(input, min_, max_); if (max_ != min_) { + // We always want to perform this algorithm even if (min_ == + // mln_min(V) and max_ == mln_max(V)) since we need to + // convert the input image towards the given type and a + // default conversion function may not exist between V and + // mln_value(I). + //FIXME: we would like to use float instead of double but we //can't for precision reasons. See ticket #179. double diff --git a/milena/mln/data/stretch_inplace.hh b/milena/mln/data/stretch_inplace.hh index a4579f1..12c8b8e 100644 --- a/milena/mln/data/stretch_inplace.hh +++ b/milena/mln/data/stretch_inplace.hh @@ -1,5 +1,4 @@ -// Copyright (C) 2013 EPITA Research and -// Development Laboratory (LRDE) +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -31,8 +30,6 @@ /// /// 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). # include <mln/estim/min_max.hh> @@ -54,6 +51,8 @@ namespace mln * * \param[in,out] ima The input image. * + * If input is filled with a single value, this function does + * nothing. * * \pre input.is_valid * @@ -67,7 +66,10 @@ namespace mln * stored inplace. * * \param[in,out] ima The input image. - * \param[out] stretched The image has changed. + * \param[out] stretched The image has changed. + * + * If input is filled with a single value, this function does + * nothing. * * \pre input.is_valid * @@ -81,39 +83,41 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - template <typename I> - inline - void - stretch_inplace(Image<I>& ima, bool& stretched) + template <typename I> + inline + void + stretch_inplace(Image<I>& ima, bool& stretched) + { + mln_trace("data::stretch_inplace"); + typedef mln_value(I) V; + mln_precondition(exact(ima).is_valid()); + + stretched = false; + V min_, max_; + estim::min_max(ima, min_, max_); + if (max_ != min_) { - mln_trace("data::stretch_inplace"); - typedef mln_value(I) V; - mln_precondition(exact(ima).is_valid()); - - V min_, max_; - estim::min_max(ima, min_, max_); - if (max_ != min_ && (mln_max(V)>max_ || mln_min(V)>min_)) - { - //FIXME: we would like to use float instead of double but we - //can't for precision reasons. See ticket #179. - double - min = double(min_), - max = double(max_), - epsilon = mln_epsilon(float), - M = mln_max(V) + 0.5f - epsilon, - m = 0.0f - 0.5f + epsilon, - a = (M - m) / (max - min), - b = (m * max - M * min) / (max - min); - fun::v2v::linear_sat<V, double, V> f(a, b); - data::transform_inplace(ima, f); - stretched = true; - } - else - { - stretched = false; - mln_trace_warning("output has no significative data!"); - } + // Already stretched ? + if (min_ == mln_min(V) && max_ == mln_max(V)) + return; + + //FIXME: we would like to use float instead of double but we + //can't for precision reasons. See ticket #179. + double + min = double(min_), + max = double(max_), + epsilon = mln_epsilon(float), + M = mln_max(V) + 0.5f - epsilon, + m = 0.0f - 0.5f + epsilon, + a = (M - m) / (max - min), + b = (m * max - M * min) / (max - min); + fun::v2v::linear_sat<V, double, V> f(a, b); + data::transform_inplace(ima, f); + stretched = true; } + // else nothing to do. + } + template <typename I> void diff --git a/milena/tests/data/Makefile.am b/milena/tests/data/Makefile.am index b733718..565987e 100644 --- a/milena/tests/data/Makefile.am +++ b/milena/tests/data/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2008, 2009, 2010 EPITA Research and Development +# Copyright (C) 2008, 2009, 2010, 2013 EPITA Research and Development # Laboratory (LRDE) # # This file is part of Olena. @@ -39,6 +39,7 @@ check_PROGRAMS = \ sort_psites \ split \ stretch \ + stretch_inplace \ transform \ transform_inplace \ update diff --git a/milena/tests/data/saturate.cc b/milena/tests/data/stretch_inplace.cc similarity index 76% copy from milena/tests/data/saturate.cc copy to milena/tests/data/stretch_inplace.cc index 4baee22..fb7b071 100644 --- a/milena/tests/data/saturate.cc +++ b/milena/tests/data/stretch_inplace.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,24 +24,27 @@ // executable file might be covered by the GNU General Public License. #include <mln/core/image/image2d.hh> -#include <mln/data/saturate.hh> -#include <mln/debug/iota.hh> - +#include <mln/data/stretch_inplace.hh> int main() { using namespace mln; - image2d<int> ima(3, 3); int vs[3][3] = { - { 2, 2, 3 }, - { 4, 5, 6 }, - { 6, 6, 6 } + { 1000, 2000, 3000 }, + { 1000, 2000, 3000 }, + { 1000, 2000, 3000 } + }; + image2d<int> ima = make::image(vs); + data::stretch_inplace(ima); + + int ws[3][3] = { + { 0, 1073741824, 2147483647 }, + { 0, 1073741824, 2147483647 }, + { 0, 1073741824, 2147483647 } }; + image2d<int> ref = make::image(ws); - image2d<int> ref = make::image(vs); - debug::iota(ima); - data::saturate_inplace(ima, 2, 6); box_fwd_piter_<point2d> p(ima.domain()); for_all(p) mln_assertion(ima(p) == ref(p)); -- 1.7.2.5
participants (1)
-
Guillaume Lazzara