https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
Start working on image virtual transformation.
* jardonnet/virtual: New.
* jardonnet/virtual/access.hh (access): Virtual access to image.
It also contains image interpolation routines.
* jardonnet/virtual/access.cc: Test file.
* jardonnet/virtual/Makefile: New.
Makefile | 2 +
access.cc | 36 +++++++++++++++++++
access.hh | 112
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+)
Index: jardonnet/virtual/access.hh
--- jardonnet/virtual/access.hh (revision 0)
+++ jardonnet/virtual/access.hh (revision 0)
@@ -0,0 +1,112 @@
+#ifndef _ACCESS_HH
+# define _ACCESS_HH
+
+# include <mln/core/image1d.hh>
+# include <mln/core/image2d.hh>
+# include <mln/math/round.hh>
+
+namespace mln
+{
+
+ namespace interpolation
+ {
+
+ struct nearest_neighbor
+ {
+
+ template <typename I, typename V>
+ mln_value(I)
+ operator()(const I& img, const V& v) const
+ {
+ mln_point(I) p = algebra::to_point<mln_point(I)>(v);
+ return img(p);
+ }
+
+ };
+
+ struct linear
+ {
+ template <typename I, typename C>
+ mln_value(I)
+ operator()(const I& img,
+ const algebra::vec<1,C>& v) const
+ {
+ // looking for img(x);
+ double x = v[0];
+
+ // p1
+ double xa = mln_point(I)::coord(v[0]);
+ double ya = img(point1d(xa));
+
+ // x makes sens in img
+ if (x == xa)
+ return img(xa);
+
+ // p2
+ double xb = mln_point(I)::coord(v[0] + 0.49999);
+ double yb = img(point1d(xb));
+
+ // Taylor-young
+ return ya + (x - xa) * (yb - ya) / (xb - xa);
+ }
+ };
+
+
+ struct bilinear
+ {
+ template <typename I, typename V>
+ mln_value(I)
+ operator()(const I& img, const V& v) const
+ {
+ // q12----r2----q22
+ // | | |
+ // | x |
+ // | | |
+ // q11----r1----q21
+
+ // looking for img(P(x,y))
+ double x = v[0];
+ double y = v[1];
+
+ double x1 = mln_point(I)::coord(v[0]);
+ double x2 = mln_point(I)::coord(v[0]+ 4.9999);
+ double y1 = mln_point(I)::coord(v[1]);
+ double y2 = mln_point(I)::coord(v[1]+ 4.9999);
+
+ point2d q11 = point2d(x1, y1);
+ point2d q12 = point2d(x1, y2);
+ point2d q21 = point2d(x2, y1);
+ point2d q22 = point2d(x2, y2);
+
+ // linear interpolation #1
+ mln_value(I) img_r1 = img(q11) * (x2 - x) / (x2 - x1) +
+ img(q21) * (x - x1) / (x2 - x1);
+
+ // linear interpolation #2
+ mln_value(I) img_r2 = img(q12) * (x2 - x) / (x2 - x1) +
+ img(q22) * (x - x1) / (x2 - x1);
+
+ // interpolating in y direction
+ return img_r1 * (y2 - y) / (y2 -y1)
+ + img_r2 * (y - y1) /(y2 - y1);
+ }
+ };
+ }
+
+ namespace access
+ {
+
+ template <typename I, typename T, typename F>
+ mln_value(I)
+ access(const I& img, const mln_point(I)& p,
+ const T& trans, const F& interp)
+ {
+ return interp(img, (trans.inv())(p));
+ }
+
+ }
+
+}
+
+#endif /* _ACCESS_HH */
+
Index: jardonnet/virtual/access.cc
--- jardonnet/virtual/access.cc (revision 0)
+++ jardonnet/virtual/access.cc (revision 0)
@@ -0,0 +1,36 @@
+
+#include <iostream>
+#include "access.hh"
+#include <mln/core/image2d.hh>
+#include <mln/fun/x2x/all.hh>
+#include <mln/debug/iota.hh>
+#include <mln/algebra/vec.hh>
+
+int main()
+{
+ using namespace mln;
+ image2d<int> img(50,50);
+ point2d p(5,5);
+ algebra::vec<2,float> v = make::vec(3,4);
+ fun::x2x::translation<2,float> t(v);
+ interpolation::nearest_neighbor nn;
+
+ debug::iota(img);
+
+ for (int i = 0; i < 50; i++)
+ {
+ for (int j = 0; j < 50; j++)
+ std::cout << img(point2d(i,j));
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ for (int i = 3; i < 53; i++)
+ {
+ for (int j = 4; j < 54; j++)
+ std::cout <<
+ access::access(img, point2d(i,j), t, nn);
+ std::cout << std::endl;
+ }
+}
Index: jardonnet/virtual/Makefile
--- jardonnet/virtual/Makefile (revision 0)
+++ jardonnet/virtual/Makefile (revision 0)
@@ -0,0 +1,2 @@
+all:
+ g++ access.cc -I../../..
\ No newline at end of file