Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_DATA_STRETCH_HH 00028 # define MLN_DATA_STRETCH_HH 00029 00038 00039 # include <mln/estim/min_max.hh> 00040 # include <mln/value/int_u.hh> 00041 # include <mln/fun/v2v/linear.hh> 00042 # include <mln/data/transform.hh> 00043 00044 00045 # include <mln/value/internal/encoding.hh> 00046 # include <iomanip> 00047 namespace mln 00048 { 00049 00050 namespace data 00051 { 00052 00063 template <typename V, typename I> 00064 mln_ch_value(I, V) 00065 stretch(const V& v, const Image<I>& input); 00066 00067 00068 # ifndef MLN_INCLUDE_ONLY 00069 00070 namespace impl 00071 { 00072 00079 // 00080 template <typename V, typename I> 00081 inline 00082 mln_ch_value(I, V) 00083 stretch(const V& v, const Image<I>& input) 00084 { 00085 trace::entering("data::impl::stretch"); 00086 00087 (void) v; 00088 mlc_converts_to(float, V)::check(); 00089 00090 mln_ch_value(I, V) output; 00091 00092 mln_value(I) min_, max_; 00093 estim::min_max(input, min_, max_); 00094 if (max_ != min_) 00095 { 00096 //FIXME: we would like to use float instead of double but we 00097 //can't for precision reasons. See ticket #179. 00098 double 00099 min = double(min_), 00100 max = double(max_), 00101 epsilon = mln_epsilon(float), 00102 M = mln_max(V) + 0.5f - epsilon, 00103 m = 0.0f - 0.5f + epsilon, 00104 a = (M - m) / (max - min), 00105 b = (m * max - M * min) / (max - min); 00106 fun::v2v::linear_sat<mln_value(I), double, V> f(a, b); 00107 output = data::transform(input, f); 00108 } 00109 else 00110 { 00111 initialize(output, input); 00112 trace::warning("output has no significative data!"); 00113 } 00114 00115 trace::exiting("data::impl::stretch"); 00116 return output; 00117 } 00118 00119 } // end of namespace mln::data::impl 00120 00121 00122 00123 // Facade 00124 00125 template <typename V, typename I> 00126 inline 00127 mln_ch_value(I, V) 00128 stretch(const V& v, const Image<I>& input) 00129 { 00130 trace::entering("data::stretch"); 00131 00132 (void) v; 00133 mln_precondition(exact(input).is_valid()); 00134 00135 mln_ch_value(I, V) output = impl::stretch(V(), input); 00136 00137 trace::exiting("data::stretch"); 00138 return output; 00139 } 00140 00141 # endif // ! MLN_INCLUDE_ONLY 00142 00143 } // end of namespace mln::data 00144 00145 } // end of namespace mln 00146 00147 00148 #endif // ! MLN_DATA_STRETCH_HH