00001 /*#****************************************************************************** 00002 ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00003 ** 00004 ** By downloading, copying, installing or using the software you agree to this license. 00005 ** If you do not agree to this license, do not download, install, 00006 ** copy or use the software. 00007 ** 00008 ** 00009 ** HVStools : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. 00010 ** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping. 00011 ** 00012 ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) 00013 ** 00014 ** Creation - enhancement process 2007-2011 00015 ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France 00016 ** 00017 ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). 00018 ** Refer to the following research paper for more information: 00019 ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 00020 ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: 00021 ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. 00022 ** 00023 ** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : 00024 ** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: 00025 ** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 00026 ** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. 00027 ** ====> more informations in the above cited Jeanny Heraults's book. 00028 ** 00029 ** License Agreement 00030 ** For Open Source Computer Vision Library 00031 ** 00032 ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00033 ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. 00034 ** 00035 ** For Human Visual System tools (hvstools) 00036 ** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. 00037 ** 00038 ** Third party copyrights are property of their respective owners. 00039 ** 00040 ** Redistribution and use in source and binary forms, with or without modification, 00041 ** are permitted provided that the following conditions are met: 00042 ** 00043 ** * Redistributions of source code must retain the above copyright notice, 00044 ** this list of conditions and the following disclaimer. 00045 ** 00046 ** * Redistributions in binary form must reproduce the above copyright notice, 00047 ** this list of conditions and the following disclaimer in the documentation 00048 ** and/or other materials provided with the distribution. 00049 ** 00050 ** * The name of the copyright holders may not be used to endorse or promote products 00051 ** derived from this software without specific prior written permission. 00052 ** 00053 ** This software is provided by the copyright holders and contributors "as is" and 00054 ** any express or implied warranties, including, but not limited to, the implied 00055 ** warranties of merchantability and fitness for a particular purpose are disclaimed. 00056 ** In no event shall the Intel Corporation or contributors be liable for any direct, 00057 ** indirect, incidental, special, exemplary, or consequential damages 00058 ** (including, but not limited to, procurement of substitute goods or services; 00059 ** loss of use, data, or profits; or business interruption) however caused 00060 ** and on any theory of liability, whether in contract, strict liability, 00061 ** or tort (including negligence or otherwise) arising in any way out of 00062 ** the use of this software, even if advised of the possibility of such damage. 00063 *******************************************************************************/ 00064 00065 #ifndef __OPENCV_CONTRIB_RETINA_HPP__ 00066 #define __OPENCV_CONTRIB_RETINA_HPP__ 00067 00068 /* 00069 * Retina.hpp 00070 * 00071 * Created on: Jul 19, 2011 00072 * Author: Alexandre Benoit 00073 */ 00074 00075 #include "opencv2/core/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support 00076 #include <valarray> 00077 00078 namespace cv 00079 { 00080 00081 enum RETINA_COLORSAMPLINGMETHOD 00082 { 00083 RETINA_COLOR_RANDOM, 00084 RETINA_COLOR_DIAGONAL, 00085 RETINA_COLOR_BAYER 00086 }; 00087 00088 class RetinaFilter; 00089 00113 class CV_EXPORTS Retina { 00114 00115 public: 00116 00117 // parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel 00118 struct RetinaParameters{ 00119 struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters 00120 OPLandIplParvoParameters():colorMode(true), 00121 normaliseOutput(true), 00122 photoreceptorsLocalAdaptationSensitivity(0.7f), 00123 photoreceptorsTemporalConstant(0.5f), 00124 photoreceptorsSpatialConstant(0.53f), 00125 horizontalCellsGain(0.0f), 00126 hcellsTemporalConstant(1.f), 00127 hcellsSpatialConstant(7.f), 00128 ganglionCellsSensitivity(0.7f){};// default setup 00129 bool colorMode, normaliseOutput; 00130 float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; 00131 }; 00132 struct IplMagnoParameters{ // Inner Plexiform Layer Magnocellular channel (IplMagno) 00133 IplMagnoParameters(): 00134 normaliseOutput(true), 00135 parasolCells_beta(0.f), 00136 parasolCells_tau(0.f), 00137 parasolCells_k(7.f), 00138 amacrinCellsTemporalCutFrequency(1.2f), 00139 V0CompressionParameter(0.95f), 00140 localAdaptintegration_tau(0.f), 00141 localAdaptintegration_k(7.f){};// default setup 00142 bool normaliseOutput; 00143 float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; 00144 }; 00145 struct OPLandIplParvoParameters OPLandIplParvo; 00146 struct IplMagnoParameters IplMagno; 00147 }; 00148 00153 Retina(Size inputSize); 00154 00164 Retina(Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0); 00165 00166 virtual ~Retina(); 00167 00171 Size inputSize(); 00172 00176 Size outputSize(); 00177 00185 void setup(std::string retinaParameterFile="", const bool applyDefaultSetupOnFailure=true); 00186 00187 00195 void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true); 00196 00204 void setup(RetinaParameters newParameters); 00205 00209 struct Retina::RetinaParameters getParameters(); 00210 00215 const std::string printSetup(); 00216 00221 virtual void write( std::string fs ) const; 00222 00223 00228 virtual void write( FileStorage& fs ) const; 00229 00245 void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7, const float photoreceptorsTemporalConstant=0.5, const float photoreceptorsSpatialConstant=0.53, const float horizontalCellsGain=0, const float HcellsTemporalConstant=1, const float HcellsSpatialConstant=7, const float ganglionCellsSensitivity=0.7); 00246 00259 void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0, const float parasolCells_tau=0, const float parasolCells_k=7, const float amacrinCellsTemporalCutFrequency=1.2, const float V0CompressionParameter=0.95, const float localAdaptintegration_tau=0, const float localAdaptintegration_k=7); 00260 00265 void run(const Mat &inputImage); 00266 00271 void getParvo(Mat &retinaOutput_parvo); 00272 00277 void getParvo(std::valarray<float> &retinaOutput_parvo); 00278 00283 void getMagno(Mat &retinaOutput_magno); 00284 00289 void getMagno(std::valarray<float> &retinaOutput_magno); 00290 00291 // original API level data accessors : get buffers addresses... 00292 const std::valarray<float> & getMagno() const; 00293 const std::valarray<float> & getParvo() const; 00294 00301 void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0); 00302 00306 void clearBuffers(); 00307 00312 void activateMovingContoursProcessing(const bool activate); 00313 00318 void activateContoursProcessing(const bool activate); 00319 00320 protected: 00321 // Parameteres setup members 00322 RetinaParameters _retinaParameters; // structure of parameters 00323 00324 // Retina model related modules 00325 std::valarray<float> _inputBuffer; 00326 00327 // pointer to retina model 00328 RetinaFilter* _retinaFilter; 00329 00338 void _convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, Mat &outBuffer); 00339 00346 bool _convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std::valarray<float> &outputValarrayMatrix); 00347 00349 void _init(const Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0); 00350 00351 00352 }; 00353 00354 } 00355 #endif /* __OPENCV_CONTRIB_RETINA_HPP__ */ 00356