mimas::warp< Tensor, T > Class Template Reference
[Image warping]

Image to image transform. More...

#include <warp.h>

Inheritance diagram for mimas::warp< Tensor, T >:

Inheritance graph
[legend]
Collaboration diagram for mimas::warp< Tensor, T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef boost::numeric::ublas::vector<
double
Vector

Public Member Functions

 warp (const Tensor &aT, T aBackground)
 Constructor.
mimas::image< T > operator() (const mimas::image< T > &in) const
 Warp image.

Protected Attributes

Tensor t
 The tensor.
background
 Background value for undefined pixels.

Detailed Description

template<class Tensor, typename T>
class mimas::warp< Tensor, T >

Image to image transform.

The image $g\in\mathrm{R}^2\mapsto\mathrm{T}$ is warped using a 2D-tensor $t\in\mathrm{R}^2\mapsto\mathrm{R}^2$: $g^\prime(\vec{x})=g(\vec{x}+t(\vec{x}-\vec{m}))$, where $\vec{m}$ is the middle of the image.

You need to define your own tensor function as function object:

// Lenscorrection
// Bala Amavasai (bala@amavasai.org)
// Jan Wedekind (jan at wedesoft.de)
// Mon Aug 23 14:37:05 UTC 2004

#include <boost/numeric/ublas/vector.hpp>
#include <functional>
#include <iostream>
#include <fstream>
#include "image.h"
#include "image_fileinput.h"
#include "image_mesaoutput.h"
#include "vectorfield.h"
#include "warp.h"

using namespace mimas;
using namespace std;

typedef boost::numeric::ublas::vector< double > Vector;

class LensCorrection: public std::unary_function< Vector, Vector >
{
 public:
  LensCorrection( double _pixelSizeX, double _pixelSizeY,
                  double _focalLength, double _curvature ):
    factorX( _pixelSizeX / _focalLength ),
    factorY( _pixelSizeY / _focalLength ),
    curvature( _curvature ) {}
  Vector operator()( const Vector &v ) const {
    double
      x = v( 0 ) * factorX,
      y = v( 1 ) * factorY,
      r = sqrt( x * x + y * y );
    double factor = ( 1.0 - curvature * r ) / ( 1.0 - curvature );
    Vector retVal( 2 );
    retVal( 0 ) = x * ( factor - 1.0 ) / factorX;
    retVal( 1 ) = y * ( factor - 1.0 ) / factorY;
    return retVal;    
  };
 protected:
  double factorX;
  double factorY;
  double curvature;
};

int main( int argc, char *argv[] )
{
  int retVal;
  try {
    MMERROR( argc == 3, mimasexception, ,
             "Syntax: " << argv[0] << " <image file> <correction>" );
    x11_display display;
    image_mesaoutput< unsigned char > window( &display );
    ifstream file( argv[1], ios::binary );
    image< int > inImage;
    MMERROR( file >> inImage, mimasexception, ,
             "Error reading from file \"" << argv[1] << "\"." );
    window << inImage << mimas::pause();
    vectorfield< LensCorrection > vectorField
      ( inImage.getWidth(), inImage.getHeight(),
        LensCorrection( 1.0 / inImage.getHeight(),
                        1.0 / inImage.getHeight(),
                        0.5, atof( argv[2] ) ) );

    // Instantiate warp-object.
    warp< vectorfield< LensCorrection >, int > w( vectorField, 0 );
    // Apply warp-object.
    image< int > outImage( w( inImage ) );
    
    // Display result.
    window << outImage << mimas::pause();
    retVal = 0;
  } catch ( exception &e ) {
    cerr << e.what() << endl;
    retVal = 1;
  };
  return retVal;
}

Todo:
Maybe the vectors passed to the tensor should be scaled, so that the tensor-specification will be independent of the image resolution.
Todo:
Provide functionality for using interpolation.
Author:
Jan Wedekind (jan at wedesoft.de)
Date:
Wed Jul 07 14:13:00 UTC 2004
See also:
vectorfield

Definition at line 28 of file warp.h.


Member Typedef Documentation

template<class Tensor, typename T>
typedef boost::numeric::ublas::vector< double > mimas::warp< Tensor, T >::Vector

Definition at line 31 of file warp.h.


Constructor & Destructor Documentation

template<class Tensor, typename T>
mimas::warp< Tensor, T >::warp ( const Tensor &  aT,
aBackground 
) [inline]

Constructor.

Parameters:
aT tensor to apply to images.
aBackground Background value to use for undefined pixels.

Definition at line 35 of file warp.h.


Member Function Documentation

template<class Tensor, typename T>
mimas::image< T > mimas::warp< Tensor, T >::operator() ( const mimas::image< T > &  in  )  const

Warp image.

Parameters:
in Input image.
Returns:
Output image.


Member Data Documentation

template<class Tensor, typename T>
Tensor mimas::warp< Tensor, T >::t [protected]

The tensor.

Definition at line 42 of file warp.h.

template<class Tensor, typename T>
T mimas::warp< Tensor, T >::background [protected]

Background value for undefined pixels.

Definition at line 44 of file warp.h.


The documentation for this class was generated from the following file:
[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:48 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...