36 #ifndef VIGRA_AFFINEGEOMETRY_HXX
37 #define VIGRA_AFFINEGEOMETRY_HXX
39 #include "mathutil.hxx"
41 #include "tinyvector.hxx"
42 #include "splineimageview.hxx"
43 #include "multi_shape.hxx"
66 linalg::TemporaryMatrix<double> ret(identityMatrix<double>(3));
79 linalg::TemporaryMatrix<double> ret(identityMatrix<double>(3));
80 ret(0,0) = scalingFactor;
81 ret(1,1) = scalingFactor;
92 linalg::TemporaryMatrix<double> ret(identityMatrix<double>(3));
105 linalg::TemporaryMatrix<double> ret(identityMatrix<double>(3));
118 linalg::TemporaryMatrix<double> ret(identityMatrix<double>(3));
165 template <
int ORDER,
class T,
166 class DestIterator,
class DestAccessor>
167 void rotateImage(SplineImageView<ORDER, T>
const & src,
168 DestIterator
id, DestAccessor dest,
169 double angleInDegree, TinyVector<double, 2>
const & center)
172 int h = src.height();
174 double angle = angleInDegree/180.0;
178 for(
int y = 0; y < h; ++y, ++
id.y)
180 typename DestIterator::row_iterator rd =
id.rowIterator();
181 double sy = (y - center[1])*c - center[0]*s + center[1];
182 double sx = -(y - center[1])*s - center[0]*c + center[0];
183 for(
int x=0; x < w; ++x, ++rd, sx += c, sy += s)
185 if(src.isInside(sx, sy))
186 dest.set(src(sx, sy), rd);
191 template <
int ORDER,
class T,
192 class DestIterator,
class DestAccessor>
194 rotateImage(SplineImageView<ORDER, T>
const & src,
195 pair<DestIterator, DestAccessor> dest,
196 double angleInDegree, TinyVector<double, 2>
const & center)
198 rotateImage(src, dest.first, dest.second, angleInDegree, center);
201 template <
int ORDER,
class T,
202 class DestIterator,
class DestAccessor>
204 rotateImage(SplineImageView<ORDER, T>
const & src,
205 DestIterator
id, DestAccessor dest,
206 double angleInDegree)
208 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
209 rotateImage(src,
id, dest, angleInDegree, center);
212 template <
int ORDER,
class T,
213 class DestIterator,
class DestAccessor>
215 rotateImage(SplineImageView<ORDER, T>
const & src,
216 pair<DestIterator, DestAccessor> dest,
217 double angleInDegree)
219 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
220 rotateImage(src, dest.first, dest.second, angleInDegree, center);
223 template <
int ORDER,
class T,
226 rotateImage(SplineImageView<ORDER, T>
const & src,
227 MultiArrayView<2, T2, S2> dest,
228 double angleInDegree, TinyVector<double, 2>
const & center)
230 rotateImage(src, destImage(dest), angleInDegree, center);
233 template <
int ORDER,
class T,
236 rotateImage(SplineImageView<ORDER, T>
const & src,
237 MultiArrayView<2, T2, S2> dest,
238 double angleInDegree)
240 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0);
241 rotateImage(src, destImage(dest), angleInDegree, center);
365 template <
int ORDER,
class T,
366 class DestIterator,
class DestAccessor,
369 DestIterator dul, DestIterator dlr, DestAccessor dest,
370 MultiArrayView<2, double, C>
const & affineMatrix)
373 affineMatrix(2,0) == 0.0 && affineMatrix(2,1) == 0.0 && affineMatrix(2,2) == 1.0,
374 "affineWarpImage(): matrix doesn't represent an affine transformation with homogeneous 2D coordinates.");
377 double w = dlr.x - dul.x;
378 double h = dlr.y - dul.y;
380 for(
double y = 0.0; y < h; ++y, ++dul.y)
382 typename DestIterator::row_iterator rd = dul.rowIterator();
383 for(
double x=0.0; x < w; ++x, ++rd)
385 double sx = x*affineMatrix(0,0) + y*affineMatrix(0,1) + affineMatrix(0,2);
386 double sy = x*affineMatrix(1,0) + y*affineMatrix(1,1) + affineMatrix(1,2);
387 if(src.isInside(sx, sy))
388 dest.set(src(sx, sy), rd);
393 template <
int ORDER,
class T,
394 class DestIterator,
class DestAccessor,
398 triple<DestIterator, DestIterator, DestAccessor> dest,
399 MultiArrayView<2, double, C>
const & affineMatrix)
401 affineWarpImage(src, dest.first, dest.second, dest.third, affineMatrix);
404 template <
int ORDER,
class T,
409 MultiArrayView<2, T2, S2> dest,
410 MultiArrayView<2, double, C>
const & affineMatrix)
REAL sin_pi(REAL x)
sin(pi*x).
Definition: mathutil.hxx:1204
MultiArrayIndex rowCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:671
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
REAL cos_pi(REAL x)
cos(pi*x).
Definition: mathutil.hxx:1242
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
MultiArrayIndex columnCount(const MultiArrayView< 2, T, C > &x)
Definition: matrix.hxx:684
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)