projective_registration.hxx
|
 |
36 #ifndef VIGRA_PROJECTIVE_REGISTRATION_HXX 37 #define VIGRA_PROJECTIVE_REGISTRATION_HXX 39 #include "mathutil.hxx" 41 #include "linear_solve.hxx" 42 #include "tinyvector.hxx" 43 #include "splineimageview.hxx" 63 template <
class SrcPo
intIterator,
class DestPo
intIterator>
64 linalg::TemporaryMatrix<double>
73 vigra_assert(size >= 4,
74 "projectiveMatrix2DFromCorrespondingPoints(): need at least four corresponding points.");
76 vigra::Matrix<double> A(2*size,8, 0.0), b(2*size,1), res(8,1);
77 for (
int i =0; i<size; ++i, ++s, ++d)
81 A(i,0)=(*d)[0]; A(i,1)=(*d)[1]; A(i,2)=1; A(i,3)=0; A(i,4)=0; A(i,5)=0; A(i,6)=-1*((*d)[0])*((*s)[0]); A(i,7)=-1*((*d)[1])*((*s)[0]);
84 A(size+i,0)=0; A(size+i,1)=0; A(size+i,2)=0; A(size+i,3)=(*d)[0]; A(size+i,4)=(*d)[1]; A(size+i,5)=1; A(size+i,6)=-1*((*d)[0])*((*s)[1]); A(size+i,7)=-1*((*d)[1])*((*s)[1]);
90 "projectiveMatrix2DFromCorrespondingPoints(): singular solution matrix.");
92 linalg::TemporaryMatrix<double> projectiveMat(3,3);
93 projectiveMat(0,0) = res(0,0); projectiveMat(0,1) = res(1,0); projectiveMat(0,2) = res(2,0);
94 projectiveMat(1,0) = res(3,0); projectiveMat(1,1) = res(4,0); projectiveMat(1,2) = res(5,0);
95 projectiveMat(2,0) = res(6,0); projectiveMat(2,1) = res(7,0); projectiveMat(2,2) = 1;
188 template <
int ORDER,
class T,
189 class DestIterator,
class DestAccessor,
192 DestIterator dul, DestIterator dlr, DestAccessor dest,
195 vigra_precondition(
rowCount(projectiveMatrix) == 3 &&
columnCount(projectiveMatrix) == 3 && projectiveMatrix(2,2) == 1.0,
196 "projectiveWarpImage(): matrix doesn't represent an projective transformation with homogeneous 2D coordinates.");
199 double w = dlr.x - dul.x;
200 double h = dlr.y - dul.y;
202 for(
double y = 0.0; y < h; ++y, ++dul.y)
204 typename DestIterator::row_iterator rd = dul.rowIterator();
205 for(
double x=0.0; x < w; ++x, ++rd)
207 double fac = 1.0/(x*projectiveMatrix(2,0) + y*projectiveMatrix(2,1) + 1);
208 double sx = (x*projectiveMatrix(0,0) + y*projectiveMatrix(0,1) + projectiveMatrix(0,2)) * fac;
209 double sy = (x*projectiveMatrix(1,0) + y*projectiveMatrix(1,1) + projectiveMatrix(1,2)) * fac;
211 dest.set(src(sx, sy), rd);
216 template <
int ORDER,
class T,
217 class DestIterator,
class DestAccessor,
221 triple<DestIterator, DestIterator, DestAccessor> dest,
228 template <
int ORDER,
class T,
bool isInside(double x, double y) const
Definition: splineimageview.hxx:487
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:669
Definition: accessor.hxx:43
void projectiveWarpImage(...)
Warp an image according to an projective transformation.
doxygen_overloaded_function(template<... > void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
linalg::TemporaryMatrix< double > projectiveMatrix2DFromCorrespondingPoints(SrcPointIterator s, SrcPointIterator send, DestPointIterator d)
Create homogeneous matrix that maps corresponding points onto each other.
Definition: projective_registration.hxx:65
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:682
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:652
Create a continuous view onto a discrete image using splines.
Definition: splineimageview.hxx:99