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