mexopencv  3.4.1
MEX interface for OpenCV library
fastNlMeansDenoisingColored.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 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  float h = 3;
30  float hColor = 3;
31  int templateWindowSize = 7;
32  int searchWindowSize = 21;
33  bool flip = false;
34  for (int i=1; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "H")
37  h = rhs[i+1].toFloat();
38  else if (key == "HColor")
39  hColor = rhs[i+1].toFloat();
40  else if (key == "TemplateWindowSize")
41  templateWindowSize = rhs[i+1].toInt();
42  else if (key == "SearchWindowSize")
43  searchWindowSize = rhs[i+1].toInt();
44  else if (key == "FlipChannels")
45  flip = rhs[i+1].toBool();
46  else
47  mexErrMsgIdAndTxt("mexopencv:error",
48  "Unrecognized option %s", key.c_str());
49  }
50 
51  // Process
52  Mat src(rhs[0].toMat(CV_8U)), dst;
53  if (flip && (src.channels() == 3 || src.channels() == 4)) {
54  // MATLAB's default is RGB/RGBA while OpenCV's is BGR/BGRA
55  cvtColor(src, src, (src.channels()==3 ?
57  }
58  fastNlMeansDenoisingColored(src, dst, h, hColor,
59  templateWindowSize, searchWindowSize);
60  if (flip && (dst.channels() == 3 || dst.channels() == 4)) {
61  // OpenCV's default is BGR/BGRA while MATLAB's is RGB/RGBA
62  cvtColor(dst, dst, (dst.channels()==3 ?
64  }
65  plhs[0] = MxArray(dst);
66 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
COLOR_RGB2BGR
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
COLOR_RGBA2BGRA
COLOR_BGR2RGB
#define CV_8U
void fastNlMeansDenoisingColored(InputArray src, OutputArray dst, float h_luminance, float photo_render, int search_window=21, int block_size=7, Stream &stream=Stream::Null())
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
COLOR_BGRA2RGBA
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)
void flip(InputArray src, OutputArray dst, int flipCode)
cv::Mat toMat() const
int channels() const