KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reflect.h
Go to the documentation of this file.
1 // reflect.h - reflect any type image into its region of interest
3 // Author: Doron Tal
4 // Date created: March, 2000
5 
6 #ifndef _REFLECT_H
7 #define _REFLECT_H
8 
9 #include <assert.h>
10 #include "wrap_dtlib_cpp/img.h"
11 
12 namespace DTLib {
13 
14  // POSTCOND: centers InImg in OutImg and refelcts it, leaving
15  // OutImg with the ROI set to exactly contain InImg.
16  template <class T>
17  void Reflect(CImg<T>& InImg, CImg<T>& OutImg) {
18  const int InWidth = InImg.Width();
19  const int InHeight = InImg.Height();
20  const int WidthDiff = OutImg.Width()-InWidth;
21  const int HeightDiff = OutImg.Height()-InHeight;
22  assert(WidthDiff >= 0);
23  assert(HeightDiff >= 0);
24  const int HalfWidthDiff = WidthDiff/2;
25  const int HalfHeightDiff = HeightDiff/2;
26  OutImg.ChangeROI(HalfWidthDiff, HalfWidthDiff+InWidth,
27  HalfHeightDiff, HalfHeightDiff+InHeight);
28  OutImg.CopyFromBuf(InImg.pBuffer());
29  OutImg.ReflectToROI(); // here is where the reflect's done!
30  };
31 
32 } // namespace DTLib {
33 
34 #endif /* #ifndef _REFLECT_H */
void ChangeROI(const int StartX, const int EndX, const int StartY, const int EndY)
Definition: img.h:1006
void CopyFromBuf(T *pBuf)
Definition: img.h:1218
Definition: img.h:51
int Width() const
Definition: img.h:135
void Reflect(CImg< T > &InImg, CImg< T > &OutImg)
Definition: reflect.h:17
int Height() const
Definition: img.h:138
void ReflectToROI()
Definition: img.h:1139
T * pBuffer()
Definition: img.h:148