mexopencv  0.1
mex interface for opencv library
balanceWhite.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/xphoto.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::xphoto;
13 
14 namespace {
16 const ConstMap<string,int> WhitebalanceTypeMap = ConstMap<string,int>
17  ("Simple", cv::xphoto::WHITE_BALANCE_SIMPLE)
18  ("GrayWorld", cv::xphoto::WHITE_BALANCE_GRAYWORLD);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int algorithmType = cv::xphoto::WHITE_BALANCE_SIMPLE;
38  float inputMin = 0.0f;
39  float inputMax = 255.0f;
40  float outputMin = 0.0f;
41  float outputMax = 255.0f;
42  for (int i=1; i<nrhs; i+=2) {
43  string key(rhs[i].toString());
44  if (key == "Type")
45  algorithmType = WhitebalanceTypeMap[rhs[i+1].toString()];
46  else if (key == "InputMin")
47  inputMin = rhs[i+1].toFloat();
48  else if (key == "InputMax")
49  inputMax = rhs[i+1].toFloat();
50  else if (key == "OutputMin")
51  outputMin = rhs[i+1].toFloat();
52  else if (key == "OutputMax")
53  outputMax = rhs[i+1].toFloat();
54  else
55  mexErrMsgIdAndTxt("mexopencv:error",
56  "Unrecognized option %s", key.c_str());
57  }
58 
59  // Process
60  Mat src(rhs[0].toMat()),
61  dst;
62  balanceWhite(src, dst, algorithmType,
63  inputMin, inputMax, outputMin, outputMax);
64  plhs[0] = MxArray(dst);
65 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927