mexopencv  0.1
mex interface for opencv library
bilateralFilter.cpp
Go to the documentation of this file.
1 
14 #include "mexopencv.hpp"
15 using namespace std;
16 using namespace cv;
17 
25 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
26 {
27  // Check the number of arguments
28  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
29 
30  // Argument vector
31  vector<MxArray> rhs(prhs, prhs+nrhs);
32 
33  // Option processing
34  int d = 7;
35  double sigmaColor = 50.0;
36  double sigmaSpace = 50.0;
37  int borderType = cv::BORDER_DEFAULT;
38  for (int i=1; i<nrhs; i+=2) {
39  string key(rhs[i].toString());
40  if (key=="Diameter")
41  d = rhs[i+1].toInt();
42  else if (key=="SigmaColor")
43  sigmaColor = rhs[i+1].toDouble();
44  else if (key=="SigmaSpace")
45  sigmaSpace = rhs[i+1].toDouble();
46  else if (key=="BorderType")
47  borderType = BorderType[rhs[i+1].toString()];
48  else
49  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
50  }
51 
52  // Process
53  Mat src(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)), dst;
54  bilateralFilter(src, dst, d, sigmaColor, sigmaSpace, borderType);
55  plhs[0] = MxArray(dst);
56 }
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
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.