00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00097
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 }
00120
00121
00122
00123
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 }
00144
00145 }
00146
00147
00148 #endif // ! MLN_DATA_STRETCH_HH