9 #include "opencv2/photo.hpp" 18 map<int,Ptr<TonemapReinhard> > obj_;
25 Ptr<TonemapReinhard> create_TonemapReinhard(
26 vector<MxArray>::const_iterator first,
27 vector<MxArray>::const_iterator last)
29 ptrdiff_t len = std::distance(first, last);
32 float intensity = 0.0f;
33 float light_adapt = 1.0f;
34 float color_adapt = 0.0f;
35 for (; first != last; first += 2) {
36 string key(first->toString());
37 const MxArray& val = *(first + 1);
40 else if (key ==
"Intensity")
41 intensity = val.toFloat();
42 else if (key ==
"LightAdaptation")
43 light_adapt = val.toFloat();
44 else if (key ==
"ColorAdaptation")
45 color_adapt = val.toFloat();
47 mexErrMsgIdAndTxt(
"mexopencv:error",
48 "Unrecognized option %s", key.c_str());
50 return createTonemapReinhard(gamma, intensity, light_adapt, color_adapt);
61 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
67 vector<MxArray> rhs(prhs, prhs+nrhs);
68 int id = rhs[0].toInt();
69 string method(rhs[1].toString());
72 if (method ==
"new") {
74 obj_[++last_id] = create_TonemapReinhard(
75 rhs.begin() + 2, rhs.end());
81 Ptr<TonemapReinhard> obj = obj_[id];
82 if (method ==
"delete") {
86 else if (method ==
"clear") {
90 else if (method ==
"load") {
91 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
93 bool loadFromString =
false;
94 for (
int i=3; i<nrhs; i+=2) {
95 string key(rhs[i].toString());
97 objname = rhs[i+1].toString();
98 else if (key ==
"FromString")
99 loadFromString = rhs[i+1].toBool();
101 mexErrMsgIdAndTxt(
"mexopencv:error",
102 "Unrecognized option %s", key.c_str());
111 FileStorage fs(rhs[2].toString(), FileStorage::READ +
112 (loadFromString ? FileStorage::MEMORY : 0));
113 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
115 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
118 else if (method ==
"save") {
120 obj->save(rhs[2].toString());
122 else if (method ==
"empty") {
124 plhs[0] =
MxArray(obj->empty());
126 else if (method ==
"getDefaultName") {
128 plhs[0] =
MxArray(obj->getDefaultName());
130 else if (method ==
"process") {
132 Mat src(rhs[2].toMat(CV_32F)), dst;
133 obj->process(src, dst);
136 else if (method ==
"get") {
138 string prop(rhs[2].toString());
140 plhs[0] =
MxArray(obj->getGamma());
141 else if (prop ==
"Intensity")
142 plhs[0] =
MxArray(obj->getIntensity());
143 else if (prop ==
"LightAdaptation")
144 plhs[0] =
MxArray(obj->getLightAdaptation());
145 else if (prop ==
"ColorAdaptation")
146 plhs[0] =
MxArray(obj->getColorAdaptation());
148 mexErrMsgIdAndTxt(
"mexopencv:error",
149 "Unrecognized property %s", prop.c_str());
151 else if (method ==
"set") {
153 string prop(rhs[2].toString());
155 obj->setGamma(rhs[3].toFloat());
156 else if (prop ==
"Intensity")
157 obj->setIntensity(rhs[3].toFloat());
158 else if (prop ==
"LightAdaptation")
159 obj->setLightAdaptation(rhs[3].toFloat());
160 else if (prop ==
"ColorAdaptation")
161 obj->setColorAdaptation(rhs[3].toFloat());
163 mexErrMsgIdAndTxt(
"mexopencv:error",
164 "Unrecognized property %s", prop.c_str());
167 mexErrMsgIdAndTxt(
"mexopencv:error",
168 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
float toFloat() const
Convert MxArray to float.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.