38 Size inputSize(first->toSize()); ++first;
39 bool colorMode =
true;
41 bool useRetinaLogSampling =
false;
42 float reductionFactor = 1.0f;
43 float samplingStrength = 10.0f;
44 for (; first != last; first += 2) {
45 string key(first->toString());
46 const MxArray& val = *(first + 1);
47 if (key ==
"ColorMode")
49 else if (key ==
"ColorSamplingMethod")
51 else if (key ==
"UseRetinaLogSampling")
52 useRetinaLogSampling = val.toBool();
53 else if (key ==
"ReductionFactor")
54 reductionFactor = val.toFloat();
55 else if (key ==
"SamplingStrength")
56 samplingStrength = val.toFloat();
59 "Unrecognized option %s", key.c_str());
62 useRetinaLogSampling, reductionFactor, samplingStrength);
71 RetinaParameters::OPLandIplParvoParameters &OPLandIplParvo,
77 for (; first != last; first += 2) {
78 string key(first->toString());
79 const MxArray& val = *(first + 1);
80 if (key ==
"ColorMode")
81 OPLandIplParvo.colorMode = val.
toBool();
82 else if (key ==
"NormaliseOutput")
83 OPLandIplParvo.normaliseOutput = val.toBool();
84 else if (key ==
"PhotoreceptorsLocalAdaptationSensitivity")
85 OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity = val.toFloat();
86 else if (key ==
"PhotoreceptorsTemporalConstant")
87 OPLandIplParvo.photoreceptorsTemporalConstant = val.toFloat();
88 else if (key ==
"PhotoreceptorsSpatialConstant")
89 OPLandIplParvo.photoreceptorsSpatialConstant = val.toFloat();
90 else if (key ==
"HorizontalCellsGain")
91 OPLandIplParvo.horizontalCellsGain = val.toFloat();
92 else if (key ==
"HCellsTemporalConstant")
93 OPLandIplParvo.hcellsTemporalConstant = val.toFloat();
94 else if (key ==
"HCellsSpatialConstant")
95 OPLandIplParvo.hcellsSpatialConstant = val.toFloat();
96 else if (key ==
"GanglionCellsSensitivity")
97 OPLandIplParvo.ganglionCellsSensitivity = val.toFloat();
100 "Unrecognized option %s", key.c_str());
110 RetinaParameters::IplMagnoParameters &IplMagno,
116 for (; first != last; first += 2) {
117 string key(first->toString());
118 const MxArray& val = *(first + 1);
119 if (key ==
"NormaliseOutput")
120 IplMagno.normaliseOutput = val.
toBool();
121 else if (key ==
"ParasolCellsBeta")
122 IplMagno.parasolCells_beta = val.toFloat();
123 else if (key ==
"ParasolCellsTau")
124 IplMagno.parasolCells_tau = val.toFloat();
125 else if (key ==
"ParasolCellsK")
126 IplMagno.parasolCells_k = val.toFloat();
127 else if (key ==
"AmacrinCellsTemporalCutFrequency")
128 IplMagno.amacrinCellsTemporalCutFrequency = val.toFloat();
129 else if (key ==
"V0CompressionParameter")
130 IplMagno.V0CompressionParameter = val.toFloat();
131 else if (key ==
"LocalAdaptintegrationTau")
132 IplMagno.localAdaptintegration_tau = val.toFloat();
133 else if (key ==
"LocalAdaptintegrationK")
134 IplMagno.localAdaptintegration_k = val.toFloat();
137 "Unrecognized option %s", key.c_str());
153 for (; first != last; first += 2) {
154 string key(first->toString());
156 if (key ==
"OPLandIplParvo") {
158 val.begin(), val.end());
160 else if (key ==
"IplMagno") {
162 val.begin(), val.end());
166 "Unrecognized option %s", key.c_str());
176 const char *fields[] = {
"ColorMode",
"NormaliseOutput",
177 "PhotoreceptorsLocalAdaptationSensitivity",
178 "PhotoreceptorsTemporalConstant",
"PhotoreceptorsSpatialConstant",
179 "HorizontalCellsGain",
"HCellsTemporalConstant",
180 "HCellsSpatialConstant",
"GanglionCellsSensitivity"};
182 s.
set(
"ColorMode", params.colorMode);
183 s.
set(
"NormaliseOutput", params.normaliseOutput);
184 s.
set(
"PhotoreceptorsLocalAdaptationSensitivity", params.photoreceptorsLocalAdaptationSensitivity);
185 s.
set(
"PhotoreceptorsTemporalConstant", params.photoreceptorsTemporalConstant);
186 s.
set(
"PhotoreceptorsSpatialConstant", params.photoreceptorsSpatialConstant);
187 s.
set(
"HorizontalCellsGain", params.horizontalCellsGain);
188 s.
set(
"HCellsTemporalConstant", params.hcellsTemporalConstant);
189 s.
set(
"HCellsSpatialConstant", params.hcellsSpatialConstant);
190 s.
set(
"GanglionCellsSensitivity", params.ganglionCellsSensitivity);
200 const char *fields[] = {
"NormaliseOutput",
"ParasolCellsBeta",
201 "ParasolCellsTau",
"ParasolCellsK",
202 "AmacrinCellsTemporalCutFrequency",
"V0CompressionParameter",
203 "LocalAdaptintegrationTau",
"LocalAdaptintegrationK"};
205 s.
set(
"NormaliseOutput", params.normaliseOutput);
206 s.
set(
"ParasolCellsBeta", params.parasolCells_beta);
207 s.
set(
"ParasolCellsTau", params.parasolCells_tau);
208 s.
set(
"ParasolCellsK", params.parasolCells_k);
209 s.
set(
"AmacrinCellsTemporalCutFrequency", params.amacrinCellsTemporalCutFrequency);
210 s.
set(
"V0CompressionParameter", params.V0CompressionParameter);
211 s.
set(
"LocalAdaptintegrationTau", params.localAdaptintegration_tau);
212 s.
set(
"LocalAdaptintegrationK", params.localAdaptintegration_k);
222 const char *fields[] = {
"OPLandIplParvo",
"IplMagno"};
244 int id = rhs[0].toInt();
245 string method(rhs[1].toString());
248 if (method ==
"new") {
260 if (method ==
"delete") {
265 else if (method ==
"clear") {
269 else if (method ==
"load") {
270 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
272 bool loadFromString =
false;
273 for (
int i=3; i<nrhs; i+=2) {
274 string key(rhs[i].toString());
275 if (key ==
"ObjName")
276 objname = rhs[i+1].toString();
277 else if (key ==
"FromString")
278 loadFromString = rhs[i+1].toBool();
281 "Unrecognized option %s", key.
c_str());
290 FileStorage fs(rhs[2].toString(), FileStorage::READ +
291 (loadFromString ? FileStorage::MEMORY : 0));
300 else if (method ==
"save") {
302 obj->
save(rhs[2].toString());
304 else if (method ==
"empty") {
308 else if (method ==
"getDefaultName") {
312 else if (method ==
"getInputSize") {
316 else if (method ==
"getOutputSize") {
320 else if (method ==
"setup") {
321 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
322 string retinaParameterFile(rhs[2].toString());
323 bool applyDefaultSetupOnFailure =
true;
324 for (
int i=3; i<nrhs; i+=2) {
325 string key(rhs[i].toString());
326 if (key ==
"ApplyDefaultSetupOnFailure")
327 applyDefaultSetupOnFailure = rhs[i+1].toBool();
330 "Unrecognized option %s", key.
c_str());
332 obj->
setup(retinaParameterFile, applyDefaultSetupOnFailure);
334 else if (method ==
"setupParameters") {
338 obj->
setup(newParameters);
340 else if (method ==
"setupOPLandIPLParvoChannel") {
342 RetinaParameters::OPLandIplParvoParameters params;
343 params.colorMode =
true;
344 params.normaliseOutput =
true;
345 params.photoreceptorsLocalAdaptationSensitivity = 0.7f;
346 params.photoreceptorsTemporalConstant = 0.5f;
347 params.photoreceptorsSpatialConstant = 0.53f;
348 params.horizontalCellsGain = 0.f;
349 params.hcellsTemporalConstant = 1.f;
350 params.hcellsSpatialConstant = 7.f;
351 params.ganglionCellsSensitivity = 0.7f;
355 params.normaliseOutput,
356 params.photoreceptorsLocalAdaptationSensitivity,
357 params.photoreceptorsTemporalConstant,
358 params.photoreceptorsSpatialConstant,
359 params.horizontalCellsGain,
360 params.hcellsTemporalConstant,
361 params.hcellsSpatialConstant,
362 params.ganglionCellsSensitivity);
364 else if (method ==
"setupIPLMagnoChannel") {
366 RetinaParameters::IplMagnoParameters params;
367 params.normaliseOutput =
true;
368 params.parasolCells_beta = 0.f;
369 params.parasolCells_tau = 0.f;
370 params.parasolCells_k = 7.f;
371 params.amacrinCellsTemporalCutFrequency = 1.2f;
372 params.V0CompressionParameter = 0.95f;
373 params.localAdaptintegration_tau = 0.f;
374 params.localAdaptintegration_k = 7.f;
377 params.normaliseOutput,
378 params.parasolCells_beta,
379 params.parasolCells_tau,
380 params.parasolCells_k,
381 params.amacrinCellsTemporalCutFrequency,
382 params.V0CompressionParameter,
383 params.localAdaptintegration_tau,
384 params.localAdaptintegration_k);
386 else if (method ==
"getParameters") {
390 else if (method ==
"printSetup") {
394 else if (method ==
"write") {
396 string fname(rhs[2].toString());
398 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
407 else if (method ==
"run") {
410 obj->
run(inputImage);
412 else if (method ==
"applyFastToneMapping") {
415 outputToneMappedImage;
417 plhs[0] =
MxArray(outputToneMappedImage);
419 else if (method ==
"getParvo") {
421 Mat retinaOutput_parvo;
423 plhs[0] =
MxArray(retinaOutput_parvo);
425 else if (method ==
"getParvoRAW") {
427 Mat retinaOutput_parvo;
429 plhs[0] =
MxArray(retinaOutput_parvo);
431 else if (method ==
"getParvoRAW2") {
434 plhs[0] =
MxArray(retinaOutput_parvo);
436 else if (method ==
"getMagno") {
438 Mat retinaOutput_magno;
440 plhs[0] =
MxArray(retinaOutput_magno);
442 else if (method ==
"getMagnoRAW") {
444 Mat retinaOutput_magno;
446 plhs[0] =
MxArray(retinaOutput_magno);
448 else if (method ==
"getMagnoRAW2") {
451 plhs[0] =
MxArray(retinaOutput_magno);
453 else if (method ==
"setColorSaturation") {
454 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs==0);
455 bool saturateColors =
true;
456 float colorSaturationValue = 4.0f;
457 for (
int i=2; i<nrhs; i+=2) {
458 string key(rhs[i].toString());
459 if (key ==
"SaturateColors")
460 saturateColors = rhs[i+1].toBool();
461 else if (key ==
"ColorSaturationValue")
462 colorSaturationValue = rhs[i+1].toFloat();
465 "Unrecognized option %s", key.
c_str());
469 else if (method ==
"clearBuffers") {
473 else if (method ==
"activateMovingContoursProcessing") {
475 bool activate = rhs[2].toBool();
478 else if (method ==
"activateContoursProcessing") {
480 bool activate = rhs[2].toBool();
485 "Unrecognized operation %s", method.
c_str());
virtual void write(String fs) const=0
int last_id
Last object id to allocate.
IplMagnoParameters IplMagno
virtual void run(InputArray inputImage)=0
virtual Size getOutputSize()=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual void getParvoRAW(OutputArray retinaOutput_parvo)=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0
virtual void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput=true, const float photoreceptorsLocalAdaptationSensitivity=0.7f, const float photoreceptorsTemporalConstant=0.5f, const float photoreceptorsSpatialConstant=0.53f, const float horizontalCellsGain=0.f, const float HcellsTemporalConstant=1.f, const float HcellsSpatialConstant=7.f, const float ganglionCellsSensitivity=0.7f)=0
OPLandIplParvoParameters OPLandIplParvo
void createOPLandIplParvoParameters(RetinaParameters::OPLandIplParvoParameters &OPLandIplParvo, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of OPLandIplParvoParameters using options in arguments.
Ptr< Retina > create_Retina(vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of Retina using options in arguments.
void createRetinaParameters(RetinaParameters ¶ms, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of RetinaParameters using options in arguments.
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
virtual RetinaParameters getParameters()=0
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
virtual const String printSetup()=0
virtual void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0f)=0
MxArray toStruct(const RetinaParameters ¶ms)
Convert retina model parameters to scalar struct.
virtual String releaseAndGetString()
virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0
virtual void read(const FileNode &fn)
bool toBool() const
Convert MxArray to bool.
virtual void getMagno(OutputArray retinaOutput_magno)=0
void createIplMagnoParameters(RetinaParameters::IplMagnoParameters &IplMagno, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of IplMagnoParameters using options in arguments.
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...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
FileNode getFirstTopLevelNode() const
virtual void activateContoursProcessing(const bool activate)=0
virtual String getDefaultName() const
Global constant definitions.
map< int, Ptr< Retina > > obj_
Object container.
virtual void getParvo(OutputArray retinaOutput_parvo)=0
const ConstMap< string, int > RetinaColorSampMap
Retina color sampling methods.
virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0
virtual void save(const String &filename) const
virtual void setupIPLMagnoChannel(const bool normaliseOutput=true, const float parasolCells_beta=0.f, const float parasolCells_tau=0.f, const float parasolCells_k=7.f, const float amacrinCellsTemporalCutFrequency=1.2f, const float V0CompressionParameter=0.95f, const float localAdaptintegration_tau=0.f, const float localAdaptintegration_k=7.f)=0
virtual bool empty() const
virtual void activateMovingContoursProcessing(const bool activate)=0
std::map wrapper with one-line initialization and lookup method.
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
virtual void clearBuffers()=0
virtual Size getInputSize()=0