Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ConvertBayerPattern.cpp
1 #include "ConvertBayerPattern.hh"
2 #include <Filter/Convolution.hh>
3 #include <Base/Image/ImageConvert.hh>
4 #include <Base/Image/ImageBase.hh>
5 #include <Base/Image/ImageIO.hh>
6 
7 
8 using namespace BIAS;
9 using namespace std;
10 
11 
12 template <class StorageType>
14 
15 }
16 template <class StorageType>
18 
19 }
20 
21 template <class StorageType>
24  BayerDemosaicMethod method, ImageBase::EColorModel bayer_pattern)
25 {
26 
27  StorageType* pSrc = src.GetImageData();
28 
29  if(src.GetChannelCount() == 3){
30  Image<StorageType> input(src.GetWidth(), src.GetHeight(),1);
31 
32  StorageType value;
33  for(unsigned int y = 0; y < src.GetHeight(); y++){
34  for(unsigned int x = 0; x < src.GetWidth() ;x++){
35  value = 0;
36 
37  value = src.PixelValue (x,y,0) + src.PixelValue (x,y,1) + src.PixelValue (x,y,2);
38 
39  input.SetPixel (value,x,y);
40  }
41  }
42 
43  pSrc = input.GetImageData();
44  }
45 
46  dc1394bayer_method_t dcMethod = SelectMethod_(method);
47 
48  if(bayer_pattern == ImageBase::CM_invalid){
49  bayer_pattern = src.GetColorModel();
50  }
51 
52  dc1394color_filter_t coding = SelectFilter_(bayer_pattern);
53 
55 
56  switch(src.GetStorageType()){
58  dc1394_bayer_decoding_8bit((unsigned char*)pSrc,(unsigned char*)dst.GetImageData(),src.GetWidth(),src.GetHeight(),coding,dcMethod);
59  break;
60 
62  //case ImageBase::ST_unsignedint:
63  int bits = src.GetBitDepth();
64  dst.SetBitDepth(bits);
65  dc1394_bayer_decoding_16bit((unsigned short*)pSrc,(unsigned short*)dst.GetImageData(),src.GetWidth(),src.GetHeight(),coding,dcMethod,bits);
66  }
67  break;
68 
69  default:
70  return -1;
71  break;
72  }
73 
74  return 0;
75 }
76 
77 template <class StorageType>
79 
80  if(method == BAYER_DEMOSAIC_METHOD_AHD)
81  return DC1394_BAYER_METHOD_AHD;
82  else if(method == BAYER_DEMOSAIC_METHOD_BILINEAR)
83  return DC1394_BAYER_METHOD_BILINEAR;
84  else if(method == BAYER_DEMOSAIC_METHOD_HQLINEAR)
85  return DC1394_BAYER_METHOD_HQLINEAR;
86  else if(method == BAYER_DEMOSAIC_METHOD_NEAREST)
87  return DC1394_BAYER_METHOD_NEAREST;
88  else if(method == BAYER_DEMOSAIC_METHOD_SIMPLE)
89  return DC1394_BAYER_METHOD_SIMPLE;
90  else if(method == BAYER_DEMOSAIC_METHOD_VNG)
91  return DC1394_BAYER_METHOD_VNG;
92 
93  return DC1394_BAYER_METHOD_AHD;
94 }
95 
96 template <class StorageType>
98  if(bayer_pattern == ImageBase::CM_Bayer_BGGR)
99  return DC1394_COLOR_FILTER_BGGR;
100  else if(bayer_pattern == ImageBase::CM_Bayer_GBRG)
101  return DC1394_COLOR_FILTER_GBRG;
102  else if(bayer_pattern == ImageBase::CM_Bayer_GRBG)
103  return DC1394_COLOR_FILTER_GRBG;
104  else if(bayer_pattern == ImageBase::CM_Bayer_RGGB)
105  return DC1394_COLOR_FILTER_RGGB;
106 
107  return DC1394_COLOR_FILTER_RGGB;
108 }
109 
110 #define INST(type) template class ConvertBayerPattern<type>;
111 INST(unsigned char)
112 
113 #ifdef BUILD_IMAGE_USHORT
114 INST(unsigned short)
115 #endif
116 
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
Bayer_GRBG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:145
void SetBitDepth(unsigned bitdepth)
needed by ImageIO
Definition: ImageBase.hh:581
(16bit) unsigned integer image storage type
Definition: ImageBase.hh:114
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetBitDepth() const
returns the bits per channel Is not necessairily 8*sizeof(StorageType), could be fewer bits...
Definition: ImageBase.hh:344
Wrapper class to dc1394 bayer conversion class.
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
Definition: Image.hh:91
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
Bayer_GBRG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:144
BayerDemosaicMethod
methods for conversion from bayer to rgb
Definition: ImageConvert.hh:70
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
invalid (not set) image format
Definition: ImageBase.hh:129
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
int Convert(Image< StorageType > &src, Image< StorageType > &dst, BayerDemosaicMethod method=BAYER_DEMOSAIC_METHOD_AHD, ImageBase::EColorModel bayer_pattern=ImageBase::CM_invalid)
converts image with bayerpattern to rgb.