mexopencv  3.4.1
MEX interface for OpenCV library
weightedMedianFilter.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/ximgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::ximgproc;
13 
14 namespace {
17  ("EXP", cv::ximgproc::WMF_EXP)
18  ("IV1", cv::ximgproc::WMF_IV1)
19  ("IV2", cv::ximgproc::WMF_IV2)
20  ("COS", cv::ximgproc::WMF_COS)
21  ("JAC", cv::ximgproc::WMF_JAC)
22  ("OFF", cv::ximgproc::WMF_OFF);
23 }
24 
32 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
33 {
34  // Check the number of arguments
35  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
36 
37  // Argument vector
38  vector<MxArray> rhs(prhs, prhs+nrhs);
39 
40  // Option processing
41  int r = 7;
42  double sigma = 25.5;
43  int weightType = cv::ximgproc::WMF_EXP;
44  Mat mask;
45  for (int i=2; i<nrhs; i+=2) {
46  string key(rhs[i].toString());
47  if (key == "Radius")
48  r = rhs[i+1].toInt();
49  else if (key == "Sigma")
50  sigma = rhs[i+1].toDouble();
51  else if (key == "WeightType")
52  weightType = WeightTypeMap[rhs[i+1].toString()];
53  else if (key == "Mask")
54  mask = rhs[i+1].toMat(CV_8U);
55  else
56  mexErrMsgIdAndTxt("mexopencv:error",
57  "Unrecognized option %s", key.c_str());
58  }
59 
60  // Process
61  Mat src(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)),
62  joint(rhs[1].toMat(CV_8U)),
63  dst;
64  weightedMedianFilter(joint, src, dst,
65  r, sigma, weightType, mask);
66  plhs[0] = MxArray(dst);
67 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_32F
void weightedMedianFilter(InputArray joint, InputArray src, OutputArray dst, int r, double sigma=25.5, int weightType=WMF_EXP, InputArray mask=noArray())
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)
const ConstMap< string, int > WeightTypeMap
weight type options of weighted median filter
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.