mexopencv  3.4.1
MEX interface for OpenCV library
illuminationChange.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/photo.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  float alpha = 0.2f;
30  float beta = 0.4f;
31  bool flip = false;
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Alpha")
35  alpha = rhs[i+1].toFloat();
36  else if (key == "Beta")
37  beta = rhs[i+1].toFloat();
38  else if (key == "FlipChannels")
39  flip = rhs[i+1].toBool();
40  else
41  mexErrMsgIdAndTxt("mexopencv:error",
42  "Unrecognized option %s", key.c_str());
43  }
44 
45  // Process
46  Mat src(rhs[0].toMat(CV_8U)),
47  mask(rhs[1].toMat(CV_8U)),
48  dst;
49  // MATLAB's default is RGB while OpenCV's is BGR
50  if (flip) {
51  if (src.channels() == 3)
52  cvtColor(src, src, cv::COLOR_RGB2BGR);
53  if (mask.channels() == 3)
54  cvtColor(mask, mask, cv::COLOR_RGB2BGR);
55  }
56  illuminationChange(src, mask, dst, alpha, beta);
57  // OpenCV's default is BGR while MATLAB's is RGB
58  if (flip && dst.channels() == 3)
59  cvtColor(dst, dst, cv::COLOR_BGR2RGB);
60  plhs[0] = MxArray(dst);
61 }
COLOR_RGB2BGR
void illuminationChange(InputArray src, InputArray mask, OutputArray dst, float alpha=0.2f, float beta=0.4f)
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
COLOR_BGR2RGB
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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...
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
STL class.
Global constant definitions.
T c_str(T... args)
void flip(InputArray src, OutputArray dst, int flipCode)
cv::Mat toMat() const
int channels() const