Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StereoRedGreen.cpp
1 #include "StereoRedGreen.hh"
2 
3 #include <Base/Image/ImageConvert.hh>
4 #include <Base/Image/Image.hh>
5 #include <Base/Image/ImageBase.hh>
6 #include <Base/Debug/Exception.hh>
7 
8 using namespace BIAS;
9 using namespace std;
10 
11 
14 {}
15 
18 {}
19 
20 template <class StorageType>
22 Combine(const Image<StorageType>& left, const Image<StorageType>& right,
23  Image<StorageType>& result)
24 {
25  static Image<StorageType> LeftGrey, RightGrey;
26  if ( left.GetWidth() != right.GetWidth() ||
27  left.GetHeight() != right.GetHeight() ){
28  BEXCEPTION("invalid input image sizes");
29  }
30  if (ImageConvert::ToGrey(left, LeftGrey)!=0){
31  BEXCEPTION("conversion failed");
32  }
33  if (ImageConvert::ToGrey(right, RightGrey)!=0){
34  BEXCEPTION("conversion failed");
35  }
36 
37  if ( result.GetWidth() !=left .GetWidth() ||
38  result.GetHeight() != left.GetHeight() ||
39  result.GetChannelCount() != 3 ){
40  if (!result.IsEmpty()){
41  result.Release();
42  }
43  result.Init(left.GetWidth(), left.GetHeight(), 3);
44  }
45  if (result.GetColorModel() != ImageBase::CM_RGB){
47  }
48  result.SetInterleaved(true);
49 
50  StorageType *l = LeftGrey.GetImageData();
51  StorageType *r = RightGrey.GetImageData();
52  StorageType *d = result.GetImageData();
53  StorageType *e = d + result.GetPixelCount()*3;
54  while(d<e){
55  *d++ = *l++;
56  *d++ = *r++;
57  *d++ = 0;
58  }
59 
60 }
61 
62 ////////////////////////
63 // instantiation
64 ////////////////////
65 
66 #define INST(type) \
67 template void BIASImage_EXPORT StereoRedGreen::Combine<type>(const Image<type>& left, \
68  const Image<type>& right, Image<type>& result);
69 
70 INST(unsigned char)
71 INST(float)
72 
73 #ifdef BUILD_IMAGE_INT
74 INST(int)
75 #endif
76 #ifdef BUILD_IMAGE_CHAR
77 INST(char)
78 //INST(char)
79 #endif
80 #ifdef BUILD_IMAGE_SHORT
81 INST(short)
82 #endif
83 
84 #if defined(BUILD_IMAGE_USHORT)
85 INST(unsigned short)
86 #endif
87 
88 #ifdef BUILD_IMAGE_DOUBLE
89 INST(double)
90 #endif
91 #ifdef BUILD_IMAGE_UINT
92 INST(unsigned int)
93 #endif
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void SetInterleaved(bool interleaved)
Definition: ImageBase.hh:568
void Combine(const Image< StorageType > &left, const Image< StorageType > &right, Image< StorageType > &result)
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
unsigned int GetHeight() const
Definition: ImageBase.hh:319
INST(unsigned char)
The image template class for specific storage types.
Definition: Image.hh:78
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
unsigned long int GetPixelCount() const
returns number of pixels in image
Definition: ImageBase.hh:422
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey