Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageBlender.hh
1 #ifndef __ImageBlender_hh__
2 #define __ImageBlender_hh__
3 
4 #include <Base/Image/Image.hh>
5 #include <Image/Camera.hh>
6 #include <Base/Image/ImageConvert.hh>
7 #include <Filter/Gauss.hh>
8 #include <Geometry/ProjectionParametersCylindric.hh>
9 #include <Geometry/ProjectionParametersPerspective.hh>
10 #include <Image/ProjectionMapping.hh>
11 #include <Geometry/Projection.hh>
12 
13 #define WEIGHT_TYPE_NONE 0
14 #define WEIGHT_TYPE_CIRCULAR 1
15 #define WEIGHT_TYPE_CIRCULAR_FIT 2
16 #define WEIGHT_TYPE_RECTANGULAR 3
17 #define WEIGHT_TYPE_RECT_NONLINEAR 4
18 #define WEIGHT_TYPE_MIX 5 // mix between rectangular and circular
19 
20 
21 // these defines steer the orientaion of the cylinder with X/Y/Z-axes of the
22 // cameras or automatically
23 #define HORIZON_ALIGNMENT_X 0
24 #define HORIZON_ALIGNMENT_Y 1
25 #define HORIZON_ALIGNMENT_UNKNOWN 2
26 #define HORIZON_ALIGNMENT_AUTO 3
27 
28 // DEBUG LEVELS:
29 // gives some output about the whole progress
30 #define D_IMAGEBLENDER_MINIMAL 1
31 // gives some output about geometry calculation
32 #define D_IMAGEBLENDER_GEOMETRY 2
33 // gives some output about the filtering process
34 #define D_IMAGEBLENDER_FILTERING 4
35 // gives some output about the blending
36 #define D_IMAGEBLENDER_BLENDING 8
37 
38 
39 namespace BIAS {
40 
41  /** @class ImageBlender
42  * @brief maps images into a common camera and blends them seamlessly
43  *
44  * Blends a bunch of images seamlessly.
45  * You can add as many images as you like to the database using AddCamera().
46  * The projection of each camera is needed, so ensure that the camera you're
47  * adding contains a valid projection.
48  * To blend the images you've added to the database call BlendImages().
49  * Originally this class was written for panoramic image stitiching and
50  * computes a cylindrical geometry automatically from the different
51  * images. However, you can specify any projection you want as an output.
52  * In case your input images do not have the same camera center as your
53  * output image and you want this to be considered, you have to provide
54  * an output depth map, which can be used for the mapping in 3D.
55  *
56  * Blending is done by separating the image into high-pass and low-pass
57  * parts, where each part is blended over one wavelength, i.e. sharp edges
58  * are blended within 2 pixels, while the image mean is blended over
59  * the whole image size.
60  * @author Robert Wulff
61  * @date 07/2007
62  **/
63  class BIASImage_EXPORT ImageBlender : public BIAS::Debug {
64 
65  public:
66 
67  /** @brief constructor
68  @author Robert Wulff
69  @date 07/2007
70  **/
71  ImageBlender();
72 
73  /** @brief Adds an image to the database. The image must contain a valid
74  projection and a valid UUID.
75  @return 0 = OK, -1 = error
76  @author Robert Wulff
77  @date 07/2007
78  **/
79  int AddCamera(const BIAS::Camera<unsigned char>& camera,
80  unsigned int weightType = WEIGHT_TYPE_RECTANGULAR);
81 
82  /** @brief compute cylindrical geometry from added images and blend all
83  added images
84 
85  wrapper function only, calls other BlendImages
86  @param destination result image
87  @return true iff blending succeeded or false otherwise
88  @author Robert Wulff
89  @date 07/2007
90  **/
91  inline bool BlendImages(BIAS::Camera<unsigned char> &destination,
92  double gaussSigma = 1.2) {
93  // compute cyl geometry
94  ProjectionParametersCylindric ppc(-cylinderHeight_, cylinderHeight_,
95  -M_PI, M_PI,
96  cylindricImageWidth_,
97  cylindricImageHeight_);
98  ComputeCylCamGeometry(ppc);
99  return BlendImages(destination, ppc, NULL, gaussSigma);
100  }
101 
102 
103  /** @brief Blends all added images into destination with ppOut projection
104  * @param destination output image
105  * @param ppOut desired projection for output
106  * @param depthmap of destination, needed if input cameras do not have the
107  * same center as output camera, ignored if NULL
108  * @return true iff blending succeeded or false otherwise
109  * @author Robert Wulff
110  * @date 07/2007
111  **/
112  bool BlendImages(BIAS::Camera<unsigned char> &destination,
113  const ProjectionParametersBase& ppOut,
114  const BIAS::Image<float>* depthmap = NULL,
115  double gaussSigma = 1.2);
116 
117 
118  /** @brief
119  @author Robert Wulff
120  @date 10/2007
121  **/
122  inline void SetOuputImageSize(const unsigned int &newSize) {
123  cylindricImageHeight_ = newSize;
124  cylindricImageWidth_ =
125  (unsigned int)(cylindricImageHeight_ * cylinderHeight_ / M_PI);
126  };
127 
128  /** @brief
129  @author Robert Wulff
130  @date 10/2007
131  **/
132  inline unsigned int GetOuputImageSize() {
133  return cylindricImageWidth_;
134  };
135 
136  // creates a 3d model of image planes and cyl cam
137  inline void SetWriteVrml(bool flag) {writeVrml_ = flag;}
138 
139  inline void SetDrawImageBorders(bool flag) {drawImageBorders_ = flag;}
140 
141  // here come the public member variables
142 
143  /** @brief determines the alignment of the horizon
144  possible values are:
145  HORIZON_ALIGNMENT_X - horizon is in x direction (default value)
146  HORIZON_ALIGNMENT_X - horizon is in y direction
147  HORIZON_ALIGNMENT_UNKNOWN - horizon alignment is unknown
148  or mixed
149  @date 12/07
150  **/
151  inline void SetHorizonAlignment(unsigned int val) {horizonAlignment_ = val;};
152 
153  protected:
154 
155  /** @brief adds an alpha channel to RGB image, alpha can be e.g. radial
156  symmetric from image center*/
157  inline void
158  ComputeAlphaChannelWeight(BIAS::Image<float> &image,
159  unsigned int weightType =
160  WEIGHT_TYPE_RECTANGULAR);
161 
162  inline void ConvertImageToRGBA(BIAS::Image<float> &image);
163 
164  void ComputeCylCamGeometry(BIAS::ProjectionParametersCylindric &ppc);
165 
166  inline double CalcAngleToYAxis(const BIAS::Vector2<double> &v,
167  bool wantDegrees = false);
168 
169  inline double CalcAngleToXAxis(const BIAS::Vector2<double> &v,
170  bool wantDegrees = false);
171 
172  /** @brief Checks FOV of each cam and computes the cylinder's FOV
173  If mapper tries to access pixel outside of image, nasty
174  distortion effects occur. This method checks the FOV of each cam
175  and blocks access to pixels that are out of scope.
176  @author Robert Wulff
177  @date 11/07
178  **/
179  inline void CheckFov(BIAS::ProjectionParametersCylindric &ppc);
180 
181  // here come the protected member variables
183  unsigned int cylindricImageWidth_;
184  unsigned int cylindricImageHeight_;
185  unsigned int horizonAlignment_;
186 
187  std::vector<BIAS::UUID> imageIDs_;
188  std::map<BIAS::UUID, BIAS::Camera<float> > inputImages_;
189 
191 
194  };
195 }
196 #endif // __ImageBlender_hh__
unsigned int horizonAlignment_
maps images into a common camera and blends them seamlessly
Definition: ImageBlender.hh:63
unsigned int GetOuputImageSize()
BIAS::Gauss< float, float > gaussFilter_
std::map< BIAS::UUID, BIAS::Camera< float > > inputImages_
void SetDrawImageBorders(bool flag)
bool BlendImages(BIAS::Camera< unsigned char > &destination, double gaussSigma=1.2)
compute cylindrical geometry from added images and blend all added images
Definition: ImageBlender.hh:91
void SetWriteVrml(bool flag)
void SetOuputImageSize(const unsigned int &newSize)
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
unsigned int cylindricImageWidth_
std::vector< BIAS::UUID > imageIDs_
void SetHorizonAlignment(unsigned int val)
determines the alignment of the horizon possible values are: HORIZON_ALIGNMENT_X - horizon is in x di...
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
unsigned int cylindricImageHeight_