Imagine++
Interpol.h
1 // ===========================================================================
2 // Imagine++ Libraries
3 // Copyright (C) Imagine
4 // For detailed information: http://imagine.enpc.fr/software
5 // ===========================================================================
6 
7 // Interpolation
8 
9 #ifndef DOXYGEN_SHOULD_SKIP_THIS
10 
11 namespace Imagine {
12 
13 
14  template <typename T, int dim> class Image;
15  template <typename T> class PixelTraits;
16 
17  // Linear Interpolation
18  // Return type is the same as image type (a Image<int,dim> will not return a real)
19  template <typename T, int dim, typename U> inline typename PixelTraits<T>::template CastPixel<U>::value_type interpolate(const Image<T,dim> &I, FVector<U,dim> x)
20  {
21  for (int i=0;i<dim;i++) {
22  if (x[i]<0) x[i] = U(0);
23  else if (x[i] > I.size(i)-1) x[i] = U(I.size(i)-1);
24  }
25 
26  FVector<U,dim> a; // partie decimale
27  Coords<dim> c; // partie entiere
28  for (int i=0;i<dim;i++) {
29  c[i]=int(x[i]);
30  a[i]=x[i]-U(c[i]);
31  }
32 
33  typedef typename PixelTraits<T>::template CastPixel<U>::value_type return_type;
34  return_type val(U(0));
35  for (CoordsIterator<dim> p(c,c+Coords<dim>(1)) ; p != CoordsIterator<dim>() ; ++p) {
36  U f=1;
37  for (int i=0;i<dim;i++)
38  f*=((*p)[i]==c[i])?(U(1)-a[i]):a[i];
39  if (f==0)
40  continue;
41  val=val+return_type(I(*p))*f;
42  }
43  return val;
44  }
45 
46 
47 }
48 
49 #endif
Imagine++ namespace.
Definition: Array.h:7