KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rotate.h
Go to the documentation of this file.
1 // rotate.h - rotate any type image
3 // Author: Doron Tal
4 // Date Created: 1994.
5 
6 #ifndef _ROTATE_H
7 #define _ROTATE_H
8 
9 #include "wrap_dtlib_cpp/img.h"
10 #include "wrap_dtlib_cpp/affine.h"
11 
12 namespace DTLib {
13 
14  // rotate 'InImg' into 'OutImg' by angle 'Theta' (in radians)
15  // if pixels 'OutImg' get no pixels from 'InImg' then assign
16  // them the value 'BGVal'.
17 
18  template <class T>
19  void Rotate(CImg<T>& InImg, CImg<T>& OutImg,
20  const double& Theta, const T& BGVal = 0) {
21 
22  const int InputWidth = InImg.Width();
23  const int InputHeight = InImg.Height();
24 
25  const int OutputWidth = OutImg.Width();
26  const int OutputHeight = OutImg.Height();
27 
28  const int HalfInputWidth = InputWidth/2;
29  const int HalfInputHeight = InputHeight/2;
30 
31  const int HalfOutputWidth = OutputWidth/2;
32  const int HalfOutputHeight = OutputHeight/2;
33 
34  const float K = (float)(InputWidth+OutputWidth+
35  InputHeight+OutputHeight);
36 
37  const int ix1 = HalfInputWidth;
38  const int iy1 = HalfInputHeight;
39 
40  const int ox1 = HalfOutputWidth;
41  const int oy1 = HalfOutputHeight;
42 
43  const int ix2 = (int)K+HalfInputWidth;
44  const int iy2 = HalfInputHeight;
45 
46  const int ox2 = F2I(K*(float)cos(Theta))+HalfOutputWidth;
47  const int oy2 = F2I(-K*(float)sin(Theta))+HalfOutputHeight;
48 
49  CAffine ca;
50  ca.Setup(ix1, iy1, ix2, iy2, ox1, oy1, ox2, oy2);
51  ca.Transform(InImg, OutImg, BGVal);
52  }; // Rotate
53 
54 } // namespace DTLib;
55 
56 #endif /* #ifndef _ROTATE_H */
#define F2I(x)
Definition: utils.h:111
void Transform(CImg< T > &InImg, CImg< T > &OutImg, const T &BGVal=0)
Definition: affine.h:50
Definition: img.h:51
int Width() const
Definition: img.h:135
Definition: affine.h:18
void Rotate(CImg< T > &InImg, CImg< T > &OutImg, const double &Theta, const T &BGVal=0)
Definition: rotate.h:19
void Setup(const int &in_x1, const int &in_y1, const int &in_x2, const int &in_y2, const int &out_x1, const int &out_y1, const int &out_x2, const int &out_y2)
Definition: affine.cpp:22
int Height() const
Definition: img.h:138