#include <warp.h>
Inheritance diagram for mimas::warp< Tensor, T >:
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. | |
T | background |
Background value for undefined pixels. |
The image is warped using a 2D-tensor
:
, where
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; }
Definition at line 28 of file warp.h.
typedef boost::numeric::ublas::vector< double > mimas::warp< Tensor, T >::Vector |
mimas::warp< Tensor, T >::warp | ( | const Tensor & | aT, | |
T | aBackground | |||
) | [inline] |
mimas::image< T > mimas::warp< Tensor, T >::operator() | ( | const mimas::image< T > & | in | ) | const |
Warp image.
in | Input image. |
Tensor mimas::warp< Tensor, T >::t [protected] |
T mimas::warp< Tensor, T >::background [protected] |