32 #include <Base/Image/Image.hh>
33 #include <Base/Image/ImageConvert.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Image/Camera.hh>
36 #include <Utils/IOUtils.hh>
37 #include <Utils/Param.hh>
38 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
39 #include <Image/ConvertBayerPattern.hh>
49 cout <<
"use: biasapplybayer [options] in out pattern [projection]" << endl;
50 cout <<
"in: input image (mip)" << endl;
51 cout <<
"out: output image (mip)" << endl;
52 cout <<
"pattern: RGGB, GBRG, ..." << endl;
53 cout <<
"projection: camera projection params to be set (optional)" << endl;
58 int main(
int argc,
char* argv[]) {
59 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
66 "Discards half of the green pixels. "
67 "No interpolation resulting image has half resolution.",
70 if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv, fup) || fup + 2 >= argc) {
76 bool bsetproj_ =
false;
79 if (proj.
Load(argv[fup+3]) != 0) {
80 BIASERR(
"error loading projection!");
98 if (strcmp(argv[patternIndex],
"BGGR")==0) {
99 cout <<
"converting bayer BGGR to RGB (" << argv[inIndex] <<
" => " << argv[outIndex] <<
")" << endl;
100 pattern = ImageBase::CM_Bayer_BGGR;
101 }
else if (strcmp(argv[patternIndex],
"GBRG")==0) {
102 cout <<
"converting bayer GBRG to RGB (" << argv[inIndex] <<
" => " << argv[outIndex] <<
")" << endl;
103 pattern = ImageBase::CM_Bayer_GBRG;
104 }
else if (strcmp(argv[patternIndex],
"GRBG")==0) {
105 cout <<
"converting bayer GRBG to RGB (" << argv[inIndex] <<
" => " << argv[outIndex] <<
")" << endl;
106 pattern = ImageBase::CM_Bayer_GRBG;
107 }
else if (strcmp(argv[patternIndex],
"RGGB")==0) {
108 cout <<
"converting bayer RGGB to RGB (" << argv[inIndex] <<
" => " << argv[outIndex] <<
")" << endl;
109 pattern = ImageBase::CM_Bayer_RGGB;
111 cout << argv[patternIndex]<<
"? i dont know this pattern... abort!" << endl;
113 ImageIO::Load(argv[inIndex], in);
118 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
123 cout<<
"Schoen!"<<endl;
126 ImageConvert::ToRGB(in, out);
129 ImageConvert::ToRGB(in, out);
133 if(!ApplyHalfingBayerConversion(in, out)) {
141 cout <<
"warning: cannot set projection parameters" << endl;
147 ImageIO::Save(argv[outIndex], out);
160 bool even = (width%2 == 0) && (height%2 == 0);
162 BIASERR(
"cannot half this resolution!");
165 unsigned int sinkWidth = width/2;
166 unsigned int sinkHeight = height/2;
168 out.
Init(sinkWidth, sinkHeight, 3);
170 int offsetR, offsetB;
171 int index = 0, indexG = 0;
174 case ImageBase::CM_Bayer_BGGR :
179 case ImageBase::CM_Bayer_RGGB :
184 case ImageBase::CM_Bayer_GBRG :
189 case ImageBase::CM_Bayer_GRBG :
195 BIASERR(
"unknown bayer");
203 for(
unsigned int j = 0; j < sinkHeight; j++) {
204 for(
unsigned int i = 0; i < sinkWidth; i++) {
206 sinkPixels[index++] = grabedPixels[indexG+offsetR];
208 sinkPixels[index++] = grabedPixels[indexG];
210 sinkPixels[index++] = grabedPixels[indexG+offsetB];
EColorModel
These are the most often used color models.
void Release()
reimplemented from ImageBase
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
void SetColorModel(EColorModel Model)
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
void Rescale(float ratio, unsigned int cam=0)
adapt internal params to resampled image
unsigned int GetWidth() const
Wrapper class to dc1394 bayer conversion class.
This class hides the underlying projection model, like projection matrix, spherical camera...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int SetProj(const Projection &Proj)
unsigned int GetHeight() const
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
enum EColorModel GetColorModel() const
int UpdateMetaData()
copy P_ and co.
This class Param provides generic support for parameters.
invalid (not set) image format
void SetMetaData(const MetaData &m)
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.