mexopencv  0.1
mex interface for opencv library
edgePreservingFilter.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 
13 namespace {
15 const ConstMap<string,int> EdgePreseveFilterMap = ConstMap<string,int>
16  ("Recursive", cv::RECURS_FILTER)
17  ("NormConv", cv::NORMCONV_FILTER);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  int flags = cv::RECURS_FILTER;
37  float sigma_s = 60;
38  float sigma_r = 0.04f;
39  bool flip = true;
40  for (int i=1; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "Filter")
43  flags = EdgePreseveFilterMap[rhs[i+1].toString()];
44  else if (key == "SigmaS")
45  sigma_s = rhs[i+1].toFloat();
46  else if (key == "SigmaR")
47  sigma_r = rhs[i+1].toFloat();
48  else if (key == "FlipChannels")
49  flip = rhs[i+1].toBool();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54 
55  // Process
56  Mat src(rhs[0].toMat(CV_8U)), dst;
57  if (flip && src.channels() == 3) {
58  // MATLAB's default is RGB while OpenCV's is BGR
59  cvtColor(src, src, cv::COLOR_RGB2BGR);
60  }
61  edgePreservingFilter(src, dst, flags, sigma_s, sigma_r);
62  if (flip && dst.channels() == 3) {
63  // OpenCV's default is BGR while MATLAB's is RGB
64  cvtColor(dst, dst, cv::COLOR_BGR2RGB);
65  }
66  plhs[0] = MxArray(dst);
67 }
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