mexopencv  0.1
mex interface for opencv library
normalize.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=1 && (nrhs%2)!=0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  double alpha = 1.0, beta = 0.0;
29  int norm_type = cv::NORM_L2;
30  int dtype = -1;
31  Mat mask, dst;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Alpha")
35  alpha = rhs[i+1].toDouble();
36  else if (key == "Beta")
37  beta = rhs[i+1].toDouble();
38  else if (key == "NormType")
39  norm_type = (rhs[i+1].isChar()) ?
40  NormType[rhs[i+1].toString()] : rhs[i+1].toInt();
41  else if (key == "DType")
42  dtype = (rhs[i+1].isChar()) ?
43  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
44  else if (key == "Mask")
45  mask = rhs[i+1].toMat(CV_8U);
46  else if (key == "Dest") {
47  dst = rhs[i+1].toMat();
48  dtype = dst.depth();
49  }
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54 
55  // Process
56  Mat src(rhs[0].toMat());
57  if (!mask.empty() && dst.empty()) {
58  // make sure dst is initialized in case mask was used
59  int dst_depth = (dtype < 0) ? src.depth() : dtype;
60  dst.create(src.size(), CV_MAKETYPE(dst_depth, src.channels()));
61  src.convertTo(dst, dst_depth); // init as src
62  //dst.setTo(Scalar::all(0)); // init as blank
63  }
64  normalize(src, dst, alpha, beta, norm_type, dtype, mask);
65  plhs[0] = MxArray(dst);
66 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: normalize.cpp:19
Global constant definitions.
const ConstMap< std::string, int > NormType
Norm type map for option processing.
Definition: mexopencv.hpp:135