2365: Sandbox fix and check rgb bilinear interpolation.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Sandbox fix and check rgb bilinear interpolation. * jardonnet/virtual/access.hh: Fix wrong type. * jardonnet/virtual/bilinear.ppm: bilinear result. * jardonnet/virtual/access.cc: Handle border. * jardonnet/virtual/nn.ppm: NNeighbor result. * jardonnet/virtual/lena.ppm: Add test image. access.cc | 26 +- access.hh | 45 +++-- lena.ppm | 541 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 585 insertions(+), 27 deletions(-) Index: jardonnet/virtual/access.hh --- jardonnet/virtual/access.hh (revision 2364) +++ jardonnet/virtual/access.hh (working copy) @@ -29,7 +29,6 @@ operator()(const algebra::vec<n,T>& x) const { mln_psite(I) p = convert::to<mln_psite(I)>(x); - std::cout << p << std::endl; return ima(p); } @@ -101,28 +100,40 @@ double x = v[0]; double y = v[1]; - double x1 = mln_point(I)::coord(v[0]); - double x2 = mln_point(I)::coord(v[0]+ 1); - double y1 = mln_point(I)::coord(v[1]); - double y2 = mln_point(I)::coord(v[1]+ 1); - - point2d q11 = point2d(x1, y1); - point2d q12 = point2d(x1, y2); - point2d q21 = point2d(x2, y1); - point2d q22 = point2d(x2, y2); + 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); + + 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; // linear interpolation #1 - vsum img_r1 = ima(q11) * (x2 - x) / (x2 - x1) + - ima(q21) * (x - x1) / (x2 - x1); + 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 = ima(q12) * (x2 - x) / (x2 - x1) + - ima(q22) * (x - x1) / (x2 - x1); + vsum img_r2 = q12 * (x2 - x) / (x2_x1) + + q22 * (x - x1) / (x2_x1); + //std::cout << "l2 : "<< img_r2 << std::endl; // interpolating in y direction - return convert::to<mln_value(I)> - (img_r1 * (y2 - y) / (y2 -y1) - + img_r2 * (y - y1) /(y2 - y1)); + // 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; Index: jardonnet/virtual/bilinear.ppm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: jardonnet/virtual/bilinear.ppm ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: jardonnet/virtual/access.cc --- jardonnet/virtual/access.cc (revision 2364) +++ jardonnet/virtual/access.cc (working copy) @@ -6,7 +6,10 @@ #include <mln/fun/x2x/all.hh> #include <mln/debug/iota.hh> #include <mln/algebra/vec.hh> -#include <mln/io/pgm/all.hh> +#include <mln/io/ppm/all.hh> +#include <mln/border/adjust.hh> +#include <mln/border/fill.hh> +#include <mln/literal/all.hh> template < template <class> class N, typename I, typename T> @@ -21,7 +24,8 @@ for_all(p) { mln::algebra::vec<2,float> v = mln::point2d(p); - output(p) = interp(t.inv()(v)); + mln::algebra::vec<2,float> tip = t.inv()(v); + output(p) = interp(tip); } } @@ -31,15 +35,17 @@ using namespace mln; //initialization - image2d< value::rgb<8> > input(512,512,100); - mln::io::pgm::load(input, "./lena.pgm"); - image2d< value::rgb<8> > output(512,512); + image2d< value::rgb<8> > input; + io::ppm::load(input, "./lena.ppm"); + image2d< value::rgb<8> > output(input.domain()); + + border::adjust(input, 512); + border::fill(input, literal::black); //transformation - fun::x2x::translation<2,float> t(make::vec(3,4)); - fun::x2x::rotation<2,float> r(1.57, make::vec(0,1)); + fun::x2x::translation<2,float> t(make::vec(20,20)); + fun::x2x::rotation<2,float> r(0.12, make::vec(0,1)); - test1<interpolation::nearest_neighbor>(input, output, t); - mln::io::pgm::save(output,"./out.pgm"); + test1<interpolation::bilinear>(input, output, compose(r,t)); + mln::io::ppm::save(output,"./out.ppm"); } - Index: jardonnet/virtual/nn.ppm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: jardonnet/virtual/nn.ppm ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: jardonnet/virtual/lena.ppm --- jardonnet/virtual/lena.ppm (revision 0) +++ jardonnet/virtual/lena.ppm (revision 0) Cannot display.
participants (1)
-
Ugo Jardonnet