cleanup-2008 2386: Sandbox: Make use of interpolated image.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Sandbox: Make use of interpolated image. * jardonnet/virtual/access.hh (bilinear): Fix rounding error. * jardonnet/virtual/access.cc (test2): Add, make use of interpolated. * jardonnet/virtual/bilinear.ppm: Fixed result. access.cc | 29 +++++++++++++++++++++++++++-- access.hh | 50 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 60 insertions(+), 19 deletions(-) Index: jardonnet/virtual/access.hh --- jardonnet/virtual/access.hh (revision 2385) +++ jardonnet/virtual/access.hh (working copy) @@ -74,11 +74,12 @@ const I& ima; }; + template < typename I > struct bilinear : public fun::internal::selector_<const algebra::vec<3,float>, // 3,float is a dummy parameter (real is n,T) - mln_value(I), linear<I> >::ret + mln_value(I), bilinear<I> >::ret { typedef mln_value(I) result; @@ -100,44 +101,59 @@ double x = v[0]; double y = v[1]; - double x1 = mln_psite(I)::coord(v[0]); - double x2 = mln_psite(I)::coord(v[0]+ 1); - double y1 = mln_psite(I)::coord(v[1]); - double y2 = mln_psite(I)::coord(v[1]+ 1); + double x1 = std::floor(v[0]); + double x2 = std::floor(v[0]) + 1; + double y1 = std::floor(v[1]); + double y2 = std::floor(v[1]) + 1; + //if (not ima.has(point2d(x1, y1))) return mln_value(I)(); vsum q11 = ima(point2d(x1, y1)); vsum q12 = ima(point2d(x1, y2)); vsum q21 = ima(point2d(x2, y1)); vsum q22 = ima(point2d(x2, y2)); - //if (x2 - x1 == 0) - //std::cout << x2 <<" - " << x1 << std::endl; - double x2_x1 = (x2 - x1) ? x2 - x1 : 0.000001; - double y2_y1 = (y2 - y1) ? y2 - y1 : 0.000001; + double x2_x1 = x2 - x1; + double y2_y1 = y2 - y1; // linear interpolation #1 vsum img_r1 = q11 * (x2 - x) / (x2_x1) + q21 * (x - x1) / (x2_x1); - //std::cout << "l1 : "<< img_r1 << std::endl; // linear interpolation #2 - vsum img_r2 = q12 * (x2 - x) / (x2_x1) + - q22 * (x - x1) / (x2_x1); - //std::cout << "l2 : "<< img_r2 << std::endl; + vsum img_r2 = q12 * (x2 - x) / (x2_x1) + q22 * (x - x1) / (x2_x1); // interpolating in y direction - // FIXME : Sometime try to cast neg value to rgb component vsum res = (img_r1 * (y2 - y) / (y2_y1) + img_r2 * (y - y1) /(y2_y1)); - res[0] = (res[0] < 0) ? 0 : res[0]; - res[1] = (res[1] < 0) ? 0 : res[1]; - res[2] = (res[2] < 0) ? 0 : res[2]; return convert::to<mln_value(I)>(res); } const I& ima; }; + + template < typename I > + struct bicubic + : public fun::internal::selector_<const algebra::vec<3,float>, + // 3,float is a dummy parameter (real is n,T) + mln_value(I), bicubic<I> >::ret + { + typedef mln_value(I) result; + + bicubic(const I& ima) : ima(ima) {} + + template <unsigned n, typename T> + mln_value(I) + operator()(const algebra::vec<n,T>& v) const + { + typedef mln_sum(mln_value(I)) vsum; + + + //return convert::to<mln_value(I)>(res); + } + + const I& ima; + }; } namespace access Index: jardonnet/virtual/bilinear.ppm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: jardonnet/virtual/access.cc --- jardonnet/virtual/access.cc (revision 2385) +++ jardonnet/virtual/access.cc (working copy) @@ -10,6 +10,7 @@ #include <mln/border/adjust.hh> #include <mln/border/fill.hh> #include <mln/literal/all.hh> +#include <mln/core/image/interpolated.hh> template < template <class> class N, typename I, typename T> @@ -30,6 +31,23 @@ } +template <typename I, typename O, typename T> +void +test2(const I& interp, O& output, + const mln::Function_x2x<T>& t_) +{ + T t = exact(t_); + + mln_piter(I) p(output.domain()); + for_all(p) + { + mln::algebra::vec<2,float> v = mln::point2d(p); + mln::algebra::vec<2,float> tip = t.inv()(v); + output(p) = interp(tip); + } +} + + int main() { using namespace mln; @@ -39,13 +57,20 @@ io::ppm::load(input, "./lena.ppm"); image2d< value::rgb<8> > output(input.domain()); - border::adjust(input, 512); - border::fill(input, literal::black); + // adjust border + border::adjust(input, 100); + //border::fill(input, literal::black); + + interpolated< image2d< value::rgb<8> >, interpolation::bilinear> + interp(input); + + //border::adjust(interp, 20); //transformation fun::x2x::translation<2,float> t(make::vec(20,20)); fun::x2x::rotation<2,float> r(0.12, make::vec(0,1)); test1<interpolation::bilinear>(input, output, compose(r,t)); + //test2(interp, output, compose(r,t)); mln::io::ppm::save(output,"./out.ppm"); }
participants (1)
-
Ugo Jardonnet