mexopencv  3.4.1
MEX interface for OpenCV library
niBlackThreshold.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 {
21 }
22 
30 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
31 {
32  // Check the number of arguments
33  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
34 
35  // Argument vector
36  vector<MxArray> rhs(prhs, prhs+nrhs);
37 
38  // Option processing
39  double maxValue = 255;
40  int type = cv::THRESH_BINARY;
41  int blockSize = 5;
42  int binarizationMethod = cv::ximgproc::BINARIZATION_NIBLACK;
43  for (int i=2; i<nrhs; i+=2) {
44  string key(rhs[i].toString());
45  if (key == "MaxValue")
46  maxValue = rhs[i+1].toDouble();
47  else if (key == "Type")
48  type = ThreshType[rhs[i+1].toString()];
49  else if (key == "BlockSize")
50  blockSize = rhs[i+1].toInt();
51  else if (key == "Method")
52  binarizationMethod = BinarizationMethodsMap[rhs[i+1].toString()];
53  else
54  mexErrMsgIdAndTxt("mexopencv:error",
55  "Unrecognized option %s", key.c_str());
56  }
57 
58  // Process
59  Mat src(rhs[0].toMat(CV_8U)), // 8u for Sauvola, otherwise any depth
60  dst;
61  double k = rhs[1].toDouble();
62  niBlackThreshold(src, dst, maxValue, type, blockSize, k, binarizationMethod);
63  plhs[0] = MxArray(dst);
64 }
#define CV_8U
const ConstMap< std::string, int > ThreshType
Thresholding type map for option processing.
Definition: mexopencv.hpp:94
STL namespace.
void niBlackThreshold(InputArray _src, OutputArray _dst, double maxValue, int type, int blockSize, double k, int binarizationMethod=BINARIZATION_NIBLACK)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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...
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/output arguments number check.
Definition: mexopencv.hpp:181
THRESH_BINARY
STL class.
Global constant definitions.
T c_str(T... args)
const ConstMap< string, int > BinarizationMethodsMap
binarization methods map for option processing
int type() const
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const