mexopencv  0.1
mex interface for opencv library
detailEnhance.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>=1 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  float sigma_s = 10;
30  float sigma_r = 0.15f;
31  bool flip = true;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "SigmaS")
35  sigma_s = rhs[i+1].toFloat();
36  else if (key == "SigmaR")
37  sigma_r = 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)), dst;
47  if (flip && src.channels() == 3) {
48  // MATLAB's default is RGB while OpenCV's is BGR
49  cvtColor(src, src, cv::COLOR_RGB2BGR);
50  }
51  detailEnhance(src, dst, sigma_s, sigma_r);
52  if (flip && dst.channels() == 3) {
53  // OpenCV's default is BGR while MATLAB's is RGB
54  cvtColor(dst, dst, cv::COLOR_BGR2RGB);
55  }
56  plhs[0] = MxArray(dst);
57 }
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.