27 #ifndef MLN_FUN_X2V_BILINEAR_HH
28 # define MLN_FUN_X2V_BILINEAR_HH
30 # include <mln/core/image/image2d.hh>
31 # include <mln/core/concept/function.hh>
32 # include <mln/fun/internal/selector.hh>
33 # include <mln/convert/to.hh>
34 # include <mln/algebra/vec.hh>
51 template <
typename I >
55 mln_value(I), bilinear<I> >
::ret
64 operator()(const algebra::vec<2,
T>& v) const;
69 operator()(const algebra::vec<3,
T>& v) const;
75 # ifndef MLN_INCLUDE_ONLY
80 mlc_or(mlc_bool(I::psite::dim == 2), mlc_bool(I::psite::dim == 3))::check();
86 bilinear<I>::operator()(const algebra::vec<2,
T>& v)
const
88 typedef mln_sum(mln_value(I)) vsum;
100 double x1 = std::floor(v[0]);
101 double x2 = std::floor(v[0]) + 1;
102 double y1 = std::floor(v[1]);
103 double y2 = std::floor(v[1]) + 1;
106 vsum q11 = ima(
point2d(static_cast<
unsigned>(x1), static_cast<
unsigned>(y1)));
107 vsum q12 = ima(
point2d(static_cast<
unsigned>(x1), static_cast<
unsigned>(y2)));
108 vsum q21 = ima(
point2d(static_cast<
unsigned>(x2), static_cast<
unsigned>(y1)));
109 vsum q22 = ima(
point2d(static_cast<
unsigned>(x2), static_cast<
unsigned>(y2)));
111 double x2_x1 = x2 - x1;
112 double y2_y1 = y2 - y1;
115 vsum img_r1 = q11 * (x2 - x) / (x2_x1) +
116 q21 * (x - x1) / (x2_x1);
119 vsum img_r2 = q12 * (x2 - x) / (x2_x1) + q22 * (x - x1) / (x2_x1);
122 vsum res = (img_r1 * (y2 - y) / (y2_y1)
123 + img_r2 * (y - y1) / (y2_y1));
125 return
convert::to<mln_value(I)>(res);
129 template <typename I>
130 template <typename
T>
132 bilinear<I>::operator()(const algebra::vec<3,
T>& v)
const
134 typedef mln_sum(mln_value(I)) vsum;
145 double x1 = std::floor(x);
146 double x2 = std::floor(x) + 1;
147 double y1 = std::floor(y);
148 double y2 = std::floor(y) + 1;
152 vsum q11 = ima(
point3d(z, static_cast<
unsigned>(x1), static_cast<
unsigned>(y1)));
153 vsum q12 = ima(
point3d(z, static_cast<
unsigned>(x1), static_cast<
unsigned>(y2)));
154 vsum q21 = ima(
point3d(z, static_cast<
unsigned>(x2), static_cast<
unsigned>(y1)));
155 vsum q22 = ima(
point3d(z, static_cast<
unsigned>(x2), static_cast<
unsigned>(y2)));
157 double x2_x1 = x2 - x1;
158 double y2_y1 = y2 - y1;
161 vsum img_r1 = q11 * (x2 - x) / (x2_x1) +
162 q21 * (x - x1) / (x2_x1);
165 vsum img_r2 = q12 * (x2 - x) / (x2_x1) + q22 * (x - x1) / (x2_x1);
168 vsum res = (img_r1 * (y2 - y) / (y2_y1)
169 + img_r2 * (y - y1) / (y2_y1));
171 return
convert::to<mln_value(I)>(res);
175 # endif // ! MLN_INCLUDE_ONLY
184 #endif // ! MLN_FUN_X2V_BILINEAR_HH