void RetinaImpl::setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure) { try { // read parameters file if it exists or apply default setup if asked for if (!fs.isOpened()) { printf("Retina::setup: provided parameters file could not be open... skeeping configuration\n"); return; // implicit else case : retinaParameterFile could be open (it exists at least) } // OPL and Parvo init first... update at the same time the parameters structure and the retina core cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"]; currFn["colorMode"]>>_retinaParameters.OPLandIplParvo.colorMode; currFn["normaliseOutput"]>>_retinaParameters.OPLandIplParvo.normaliseOutput; currFn["photoreceptorsLocalAdaptationSensitivity"]>>_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity; currFn["photoreceptorsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant; currFn["photoreceptorsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant; currFn["horizontalCellsGain"]>>_retinaParameters.OPLandIplParvo.horizontalCellsGain; currFn["hcellsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.hcellsTemporalConstant; currFn["hcellsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.hcellsSpatialConstant; currFn["ganglionCellsSensitivity"]>>_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity; setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity); // init retina IPL magno setup... update at the same time the parameters structure and the retina core currFn=rootFn["IPLmagno"]; currFn["normaliseOutput"]>>_retinaParameters.IplMagno.normaliseOutput; currFn["parasolCells_beta"]>>_retinaParameters.IplMagno.parasolCells_beta; currFn["parasolCells_tau"]>>_retinaParameters.IplMagno.parasolCells_tau; currFn["parasolCells_k"]>>_retinaParameters.IplMagno.parasolCells_k; currFn["amacrinCellsTemporalCutFrequency"]>>_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency; currFn["V0CompressionParameter"]>>_retinaParameters.IplMagno.V0CompressionParameter; currFn["localAdaptintegration_tau"]>>_retinaParameters.IplMagno.localAdaptintegration_tau; currFn["localAdaptintegration_k"]>>_retinaParameters.IplMagno.localAdaptintegration_k; setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k); } catch(Exception &e) { printf("RetinaImpl::setup: resetting retina with default parameters\n"); if (applyDefaultSetupOnFailure) { setupOPLandIPLParvoChannel(); setupIPLMagnoChannel(); } printf("Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>%s\n", e.what()); printf("=> keeping current parameters\n"); } // report current configuration printf("%s\n", printSetup().c_str()); }
void RetinaImpl::setup(Retina::RetinaParameters newConfiguration) { // simply copy structures memcpy(&_retinaParameters, &newConfiguration, sizeof(Retina::RetinaParameters)); // apply setup setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity); setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k); }
// private method called by constructirs void Retina::_init(const std::string parametersSaveFile, const cv::Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght) { _parametersSaveFileName = parametersSaveFile; // basic error check if (inputSize.height*inputSize.width <= 0) throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "Retina::setup", "Retina.h", 0); unsigned int nbPixels=inputSize.height*inputSize.width; // resize buffers if size does not match _inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...) // allocate the retina model delete _retinaFilter; _retinaFilter = new RetinaFilter(inputSize.height, inputSize.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght); // prepare the parameter XML tree _parametersSaveFile.open(parametersSaveFile, cv::FileStorage::WRITE ); _parametersSaveFile<<"InputSize"<<"{"; _parametersSaveFile<<"height"<<inputSize.height; _parametersSaveFile<<"width"<<inputSize.width; _parametersSaveFile<<"}"; // clear all retina buffers // apply default setup setupOPLandIPLParvoChannel(); setupIPLMagnoChannel(); // write current parameters to params file _parametersSaveFile.release(); // init retina _retinaFilter->clearAllBuffers(); // report current configuration std::cout<<printSetup()<<std::endl; }
void RetinaImpl::setup(String retinaParameterFile, const bool applyDefaultSetupOnFailure) { try { // opening retinaParameterFile in read mode cv::FileStorage fs(retinaParameterFile, cv::FileStorage::READ); setup(fs, applyDefaultSetupOnFailure); } catch(Exception &e) { printf("Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>%s\n", e.what()); if (applyDefaultSetupOnFailure) { printf("Retina::setup: resetting retina with default parameters\n"); setupOPLandIPLParvoChannel(); setupIPLMagnoChannel(); } else { printf("=> keeping current parameters\n"); } } }
void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetupOnFailure) { // open specified parameters file std::cout<<"Retina::setup: setting up retina from parameter file : "<<retinaParameterFile<<std::endl; // very UGLY cases processing... to be updated... try { // rewriting a new parameter file... if (_parametersSaveFile.isOpened()) _parametersSaveFile.release(); _parametersSaveFile.open(_parametersSaveFileName, cv::FileStorage::WRITE); // opening retinaParameterFile in read mode cv::FileStorage fs(retinaParameterFile, cv::FileStorage::READ); // read parameters file if it exists or apply default setup if asked for if (!fs.isOpened()) { std::cout<<"Retina::setup: provided parameters file could not be open... skeeping configuration"<<std::endl; return; // implicit else case : retinaParameterFile could be open (it exists at least) } // preparing parameter setup bool colorMode, normaliseOutput; double photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; // OPL and Parvo init first cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"]; currFn["colorMode"]>>colorMode; currFn["normaliseOutput"]>>normaliseOutput; currFn["photoreceptorsLocalAdaptationSensitivity"]>>photoreceptorsLocalAdaptationSensitivity; currFn["photoreceptorsTemporalConstant"]>>photoreceptorsTemporalConstant; currFn["photoreceptorsSpatialConstant"]>>photoreceptorsSpatialConstant; currFn["horizontalCellsGain"]>>horizontalCellsGain; currFn["hcellsTemporalConstant"]>>hcellsTemporalConstant; currFn["hcellsSpatialConstant"]>>hcellsSpatialConstant; currFn["ganglionCellsSensitivity"]>>ganglionCellsSensitivity; setupOPLandIPLParvoChannel(colorMode, normaliseOutput, photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity); // init retina IPL magno setup currFn=rootFn["IPLmagno"]; currFn["normaliseOutput"]>>normaliseOutput; double parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; currFn["parasolCells_beta"]>>parasolCells_beta; currFn["parasolCells_tau"]>>parasolCells_tau; currFn["parasolCells_k"]>>parasolCells_k; currFn["amacrinCellsTemporalCutFrequency"]>>amacrinCellsTemporalCutFrequency; currFn["V0CompressionParameter"]>>V0CompressionParameter; currFn["localAdaptintegration_tau"]>>localAdaptintegration_tau; currFn["localAdaptintegration_k"]>>localAdaptintegration_k; setupIPLMagnoChannel(normaliseOutput, parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k); }catch(Exception &e) { std::cout<<"Retina::setup: resetting retina with default parameters"<<std::endl; if (applyDefaultSetupOnFailure) { setupOPLandIPLParvoChannel(); setupIPLMagnoChannel(); } std::cout<<"Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl; std::cout<<"=> keeping current parameters"<<std::endl; } _parametersSaveFile.release(); // close file after setup // report current configuration std::cout<<printSetup()<<std::endl; }