mexopencv  3.4.1
MEX interface for OpenCV library
bm3dDenoising.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/xphoto.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::xphoto;
13 
14 namespace {
17  ("Haar", cv::xphoto::HAAR);
18 
24 }
25 
33 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
34 {
35  // Check the number of arguments
36  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=2);
37 
38  // Argument vector
39  vector<MxArray> rhs(prhs, prhs+nrhs);
40 
41  // Option processing
42  float h = 1;
43  int templateWindowSize = 4;
44  int searchWindowSize = 16;
45  int blockMatchingStep1 = 2500;
46  int blockMatchingStep2 = 400;
47  int groupSize = 8;
48  int slidingStep = 1;
49  float beta = 2.0f;
50  int normType = cv::NORM_L2;
51  int step = cv::xphoto::BM3D_STEPALL;
52  int transformType = cv::xphoto::HAAR;
53  Mat basic;
54  for (int i=1; i<nrhs; i+=2) {
55  string key(rhs[i].toString());
56  if (key == "Basic")
57  basic = rhs[i+1].toMat(rhs[i+1].isUint16() ? CV_16U : CV_8U);
58  else if (key == "H")
59  h = rhs[i+1].toFloat();
60  else if (key == "TemplateWindowSize")
61  templateWindowSize = rhs[i+1].toInt();
62  else if (key == "SearchWindowSize")
63  searchWindowSize = rhs[i+1].toInt();
64  else if (key == "BlockMatchingStep1")
65  blockMatchingStep1 = rhs[i+1].toInt();
66  else if (key == "BlockMatchingStep2")
67  blockMatchingStep2 = rhs[i+1].toInt();
68  else if (key == "GroupSize")
69  groupSize = rhs[i+1].toInt();
70  else if (key == "SlidingStep")
71  slidingStep = rhs[i+1].toInt();
72  else if (key == "Beta")
73  beta = rhs[i+1].toFloat();
74  else if (key == "NormType")
75  normType = NormType[rhs[i+1].toString()];
76  else if (key == "Step")
77  step = (rhs[i+1].isChar()) ?
78  Bm3dStepsMap[rhs[i+1].toString()] : rhs[i+1].toInt();
79  else if (key == "TransformType")
80  transformType = TransformTypesMap[rhs[i+1].toString()];
81  else
82  mexErrMsgIdAndTxt("mexopencv:error",
83  "Unrecognized option %s", key.c_str());
84  }
85 
86  // Process
87  Mat src(rhs[0].toMat(rhs[0].isUint16() ? CV_16U : CV_8U)),
88  dst;
89  if (nlhs > 1 || !basic.empty()) {
90  bm3dDenoising(src, basic, dst, h, templateWindowSize, searchWindowSize,
91  blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep,
92  beta, normType, step, transformType);
93  if (nlhs > 1)
94  plhs[1] = MxArray(basic);
95  }
96  else
97  bm3dDenoising(src, dst, h, templateWindowSize, searchWindowSize,
98  blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep,
99  beta, normType, step, transformType);
100  plhs[0] = MxArray(dst);
101 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void bm3dDenoising(InputArray src, InputOutputArray dstStep1, OutputArray dstStep2, float h=1, int templateWindowSize=4, int searchWindowSize=16, int blockMatchingStep1=2500, int blockMatchingStep2=400, int groupSize=8, int slidingStep=1, float beta=2.0f, int normType=cv::NORM_L2, int step=cv::xphoto::BM3D_STEPALL, int transformType=cv::xphoto::HAAR)
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...
const ConstMap< string, int > TransformTypesMap
BM3D transform types for option processing.
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
#define CV_16U
const ConstMap< string, int > Bm3dStepsMap
BM3D algorithm steps for option processing.
STL class.
Global constant definitions.
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
const ConstMap< std::string, int > NormType
Norm type map for option processing.
Definition: mexopencv.hpp:150
bool empty() const
cv::Mat toMat() const