mexopencv  0.1
mex interface for opencv library
demosaicing.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
15  // Demosaicing
16  ("BayerBG2BGR", cv::COLOR_BayerBG2BGR)
17  ("BayerGB2BGR", cv::COLOR_BayerGB2BGR)
18  ("BayerRG2BGR", cv::COLOR_BayerRG2BGR)
19  ("BayerGR2BGR", cv::COLOR_BayerGR2BGR)
20  //
21  ("BayerBG2RGB", cv::COLOR_BayerBG2RGB)
22  ("BayerGB2RGB", cv::COLOR_BayerGB2RGB)
23  ("BayerRG2RGB", cv::COLOR_BayerRG2RGB)
24  ("BayerGR2RGB", cv::COLOR_BayerGR2RGB)
25  //
26  ("BayerBG2GRAY", cv::COLOR_BayerBG2GRAY)
27  ("BayerGB2GRAY", cv::COLOR_BayerGB2GRAY)
28  ("BayerRG2GRAY", cv::COLOR_BayerRG2GRAY)
29  ("BayerGR2GRAY", cv::COLOR_BayerGR2GRAY)
30  // Demosaicing using Variable Number of Gradients
31  ("BayerBG2BGR_VNG", cv::COLOR_BayerBG2BGR_VNG)
32  ("BayerGB2BGR_VNG", cv::COLOR_BayerGB2BGR_VNG)
33  ("BayerRG2BGR_VNG", cv::COLOR_BayerRG2BGR_VNG)
34  ("BayerGR2BGR_VNG", cv::COLOR_BayerGR2BGR_VNG)
35  //
36  ("BayerBG2RGB_VNG", cv::COLOR_BayerBG2RGB_VNG)
37  ("BayerGB2RGB_VNG", cv::COLOR_BayerGB2RGB_VNG)
38  ("BayerRG2RGB_VNG", cv::COLOR_BayerRG2RGB_VNG)
39  ("BayerGR2RGB_VNG", cv::COLOR_BayerGR2RGB_VNG)
40  // Edge-Aware Demosaicing
41  ("BayerBG2BGR_EA", cv::COLOR_BayerBG2BGR_EA)
42  ("BayerGB2BGR_EA", cv::COLOR_BayerGB2BGR_EA)
43  ("BayerRG2BGR_EA", cv::COLOR_BayerRG2BGR_EA)
44  ("BayerGR2BGR_EA", cv::COLOR_BayerGR2BGR_EA)
45  // Edge-Aware Demosaicing
46  ("BayerBG2RGB_EA", cv::COLOR_BayerBG2RGB_EA)
47  ("BayerGB2RGB_EA", cv::COLOR_BayerGB2RGB_EA)
48  ("BayerRG2RGB_EA", cv::COLOR_BayerRG2RGB_EA)
49  ("BayerGR2RGB_EA", cv::COLOR_BayerGR2RGB_EA);
50 }
51 
59 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
60 {
61  // Check the number of arguments
62  nargchk(nrhs>=2 && nlhs<=1);
63 
64  // Argument vector
65  vector<MxArray> rhs(prhs, prhs+nrhs);
66 
67  // Option processing
68  int dcn = 0;
69  for (int i=2; i<nrhs; i+=2) {
70  string key(rhs[i].toString());
71  if (key=="Channels")
72  dcn = rhs[i+1].toInt();
73  else
74  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
75  }
76 
77  // Process
78  Mat src(rhs[0].toMat(rhs[0].isUint16() ? CV_16U : CV_8U)), dst;
79  int code = rhs[1].isChar() ? ColorConv[rhs[1].toString()] : rhs[1].toInt();
80  demosaicing(src, dst, code, dcn);
81  plhs[0] = MxArray(dst);
82 }
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: demosaicing.cpp:59
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927