1 Retina : a Bio mimetic human retina model
2 *****************************************
11 Class which provides the main controls to the Gipsa/Listic labs human retina model. Spatio-temporal filtering modelling the two main retina information channels :
13 * foveal vision for detailled color vision : the parvocellular pathway).
15 * periphearal vision for sensitive transient signals detection (motion and events) : the magnocellular pathway.
17 **NOTE : See the Retina tutorial in the tutorial/contrib section for complementary explanations.**
19 The retina can be settled up with various parameters, by default, the retina cancels mean luminance and enforces all details of the visual scene. In order to use your own parameters, you can use at least one time the *write(std::string fs)* method which will write a proper XML file with all default parameters. Then, tweak it on your own and reload them at any time using method *setup(std::string fs)*. These methods update a *Retina::RetinaParameters* member structure that is described hereafter. ::
24 // parameters setup instance
25 struct RetinaParameters; // this class is detailled later
28 Retina (Size inputSize);
29 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);
31 // main method for input frame processing
32 void run (const Mat &inputImage);
34 // output buffers retreival methods
35 // -> foveal color vision details channel with luminance and noise correction
36 void getParvo (Mat &retinaOutput_parvo);
37 void getParvo (std::valarray< float > &retinaOutput_parvo);
38 const std::valarray< float > & getParvo () const;
39 // -> peripheral monochrome motion and events (transient information) channel
40 void getMagno (Mat &retinaOutput_magno);
41 void getMagno (std::valarray< float > &retinaOutput_magno);
42 const std::valarray< float > & getMagno () const;
44 // reset retina buffers... equivalent to closing your eyes for some seconds
47 // retreive input and output buffers sizes
51 // setup methods with specific parameters specification of global xml config file loading/write
52 void setup (std::string retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
53 void setup (FileStorage &fs, const bool applyDefaultSetupOnFailure=true);
54 void setup (RetinaParameters newParameters);
55 struct Retina::RetinaParameters getParameters ();
56 const std::string printSetup ();
57 virtual void write (std::string fs) const;
58 virtual void write (FileStorage &fs) const;
59 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);
60 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);
61 void setColorSaturation (const bool saturateColors=true, const float colorSaturationValue=4.0);
62 void activateMovingContoursProcessing (const bool activate);
63 void activateContoursProcessing (const bool activate);
68 * An example on retina tone mapping can be found at opencv_source_code/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp
69 * An example on retina tone mapping on video input can be found at opencv_source_code/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp
70 * A complete example illustrating the retina interface can be found at opencv_source_code/samples/cpp/retinaDemo.cpp
75 Class which allows the `Gipsa <http://www.gipsa-lab.inpg.fr>`_ (preliminary work) / `Listic <http://www.listic.univ-savoie.fr>`_ (code maintainer) labs retina model to be used. This class allows human retina spatio-temporal image processing to be applied on still images, images sequences and video sequences. Briefly, here are the main human retina model properties:
77 * spectral whithening (mid-frequency details enhancement)
79 * high frequency spatio-temporal noise reduction (temporal noise and high frequency spatial noise are minimized)
81 * low frequency luminance reduction (luminance range compression) : high luminance regions do not hide details in darker regions anymore
83 * local logarithmic luminance compression allows details to be enhanced even in low light conditions
85 Use : this model can be used basically for spatio-temporal video effects but also in the aim of :
87 * performing texture analysis with enhanced signal to noise ratio and enhanced details robust against input images luminance ranges (check out the parvocellular retina channel output, by using the provided **getParvo** methods)
89 * performing motion analysis also taking benefit of the previously cited properties (check out the magnocellular retina channel output, by using the provided **getMagno** methods)
91 For more information, refer to the following papers :
93 * 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>
95 * Please have a look at the reference work of Jeanny Herault that you can read in his book :
97 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.
99 This retina filter code includes the research contributions of phd/research collegues from which code has been redrawn by the author :
101 * take a look at the *retinacolor.hpp* module to discover Brice Chaix de Lavarene phD color mosaicing/demosaicing and his reference paper: B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
103 * 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. ====> more informations in the above cited Jeanny Heraults's book.
105 Demos and experiments !
106 =======================
108 **NOTE : Complementary to the following examples, have a look at the Retina tutorial in the tutorial/contrib section for complementary explanations.**
110 Take a look at the provided C++ examples provided with OpenCV :
112 * **samples/cpp/retinademo.cpp** shows how to use the retina module for details enhancement (Parvo channel output) and transient maps observation (Magno channel output). You can play with images, video sequences and webcam video.
113 Typical uses are (provided your OpenCV installation is situated in folder *OpenCVReleaseFolder*)
115 * image processing : **OpenCVReleaseFolder/bin/retinademo -image myPicture.jpg**
117 * video processing : **OpenCVReleaseFolder/bin/retinademo -video myMovie.avi**
119 * webcam processing: **OpenCVReleaseFolder/bin/retinademo -video**
121 **Note :** This demo generates the file *RetinaDefaultParameters.xml* which contains the default parameters of the retina. Then, rename this as *RetinaSpecificParameters.xml*, adjust the parameters the way you want and reload the program to check the effect.
124 * **samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp** shows how to use the retina to perform High Dynamic Range (HDR) luminance compression
126 Then, take a HDR image using bracketing with your camera and generate an OpenEXR image and then process it using the demo.
128 Typical use, supposing that you have the OpenEXR image *memorial.exr* (present in the samples/cpp/ folder)
130 **OpenCVReleaseFolder/bin/OpenEXRimages_HighDynamicRange_Retina_toneMapping memorial.exr**
132 Note that some sliders are made available to allow you to play with luminance compression.
138 Here are detailled the main methods to control the retina model
143 .. ocv:function:: Retina::Retina(Size inputSize)
144 .. ocv:function:: Retina::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 )
148 :param inputSize: the input frame size
149 :param colorMode: the chosen processing mode : with or without color processing
150 :param colorSamplingMethod: specifies which kind of color sampling will be used
151 * RETINA_COLOR_RANDOM: each pixel position is either R, G or B in a random choice
152 * RETINA_COLOR_DIAGONAL: color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR...
153 * RETINA_COLOR_BAYER: standard bayer sampling
154 :param useRetinaLogSampling: activate retina log sampling, if true, the 2 following parameters can be used
155 :param reductionFactor: only usefull if param useRetinaLogSampling=true, specifies the reduction factor of the output frame (as the center (fovea) is high resolution and corners can be underscaled, then a reduction of the output is allowed without precision leak
156 :param samplingStrenght: only usefull if param useRetinaLogSampling=true, specifies the strenght of the log scale that is applied
158 Retina::activateContoursProcessing
159 ++++++++++++++++++++++++++++++++++
161 .. ocv:function:: void Retina::activateContoursProcessing(const bool activate)
163 Activate/desactivate the Parvocellular pathway processing (contours information extraction), by default, it is activated
165 :param activate: true if Parvocellular (contours information extraction) output should be activated, false if not... if activated, the Parvocellular output can be retrieved using the **getParvo** methods
167 Retina::activateMovingContoursProcessing
168 ++++++++++++++++++++++++++++++++++++++++
170 .. ocv:function:: void Retina::activateMovingContoursProcessing(const bool activate)
172 Activate/desactivate the Magnocellular pathway processing (motion information extraction), by default, it is activated
174 :param activate: true if Magnocellular output should be activated, false if not... if activated, the Magnocellular output can be retrieved using the **getMagno** methods
179 .. ocv:function:: void Retina::clearBuffers()
181 Clears all retina buffers (equivalent to opening the eyes after a long period of eye close ;o) whatchout the temporal transition occuring just after this method call.
186 .. ocv:function:: void Retina::getParvo( Mat & retinaOutput_parvo )
187 .. ocv:function:: void Retina::getParvo( std::valarray<float> & retinaOutput_parvo )
188 .. ocv:function:: const std::valarray<float> & Retina::getParvo() const
190 Accessor of the details channel of the retina (models foveal vision)
192 :param retinaOutput_parvo: the output buffer (reallocated if necessary), format can be :
194 * a Mat, this output is rescaled for standard 8bits image processing use in OpenCV
196 * a 1D std::valarray Buffer (encoding is R1, R2, ... Rn), this output is the original retina filter model output, without any quantification or rescaling
201 .. ocv:function:: void Retina::getMagno( Mat & retinaOutput_magno )
202 .. ocv:function:: void Retina::getMagno( std::valarray<float> & retinaOutput_magno )
203 .. ocv:function:: const std::valarray<float> & Retina::getMagno() const
205 Accessor of the motion channel of the retina (models peripheral vision)
207 :param retinaOutput_magno: the output buffer (reallocated if necessary), format can be :
209 * a Mat, this output is rescaled for standard 8bits image processing use in OpenCV
211 * a 1D std::valarray Buffer (encoding is R1, R2, ... Rn), this output is the original retina filter model output, without any quantification or rescaling
213 Retina::getParameters
214 +++++++++++++++++++++
216 .. ocv:function:: Retina::RetinaParameters Retina::getParameters()
218 Retrieve the current parameters values in a *Retina::RetinaParameters* structure
220 :return: the current parameters setup
225 .. ocv:function:: Size Retina::inputSize()
227 Retreive retina input buffer size
229 :return: the retina input buffer size
234 .. ocv:function:: Size Retina::outputSize()
236 Retreive retina output buffer size that can be different from the input if a spatial log transformation is applied
238 :return: the retina output buffer size
243 .. ocv:function:: const std::string Retina::printSetup()
245 Outputs a string showing the used parameters setup
247 :return: a string which contains formatted parameters information
252 .. ocv:function:: void Retina::run(const Mat & inputImage)
254 Method which allows retina to be applied on an input image, after run, encapsulated retina module is ready to deliver its outputs using dedicated acccessors, see getParvo and getMagno methods
256 :param inputImage: the input Mat image to be processed, can be gray level or BGR coded in any format (from 8bit to 16bits)
258 Retina::setColorSaturation
259 ++++++++++++++++++++++++++
261 .. ocv:function:: void Retina::setColorSaturation(const bool saturateColors = true, const float colorSaturationValue = 4.0 )
263 Activate color saturation as the final step of the color demultiplexing process -> this saturation is a sigmoide function applied to each channel of the demultiplexed image.
265 :param saturateColors: boolean that activates color saturation (if true) or desactivate (if false)
266 :param colorSaturationValue: the saturation factor : a simple factor applied on the chrominance buffers
272 .. ocv:function:: void Retina::setup(std::string retinaParameterFile = "", const bool applyDefaultSetupOnFailure = true )
273 .. ocv:function:: void Retina::setup(FileStorage & fs, const bool applyDefaultSetupOnFailure = true )
274 .. ocv:function:: void Retina::setup(RetinaParameters newParameters)
276 Try to open an XML retina parameters file to adjust current retina instance setup => if the xml file does not exist, then default setup is applied => warning, Exceptions are thrown if read XML file is not valid
278 :param retinaParameterFile: the parameters filename
279 :param applyDefaultSetupOnFailure: set to true if an error must be thrown on error
280 :param fs: the open Filestorage which contains retina parameters
281 :param newParameters: a parameters structures updated with the new target configuration
286 .. ocv:function:: void Retina::write( std::string fs ) const
287 .. ocv:function:: void Retina::write( FileStorage& fs ) const
289 Write xml/yml formated parameters information
291 :param fs: the filename of the xml file that will be open and writen with formatted parameters information
293 Retina::setupIPLMagnoChannel
294 ++++++++++++++++++++++++++++
296 .. ocv:function:: void Retina::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 )
298 Set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel this channel processes signals output from OPL processing stage in peripheral vision, it allows motion information enhancement. It is decorrelated from the details channel. See reference papers for more details.
300 :param normaliseOutput: specifies if (true) output is rescaled between 0 and 255 of not (false)
301 :param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
302 :param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
303 :param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
304 :param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, typical value is 1.2
305 :param V0CompressionParameter: the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.95
306 :param localAdaptintegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
307 :param localAdaptintegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
309 Retina::setupOPLandIPLParvoChannel
310 ++++++++++++++++++++++++++++++++++
312 .. ocv:function:: void Retina::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 )
314 Setup the OPL and IPL parvo channels (see biologocal model) OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance (low frequency energy) IPL parvo is the OPL next processing stage, it refers to a part of the Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision. See reference papers for more informations.
316 :param colorMode: specifies if (true) color is processed of not (false) to then processing gray level image
317 :param normaliseOutput: specifies if (true) output is rescaled between 0 and 255 of not (false)
318 :param photoreceptorsLocalAdaptationSensitivity: the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
319 :param photoreceptorsTemporalConstant: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
320 :param photoreceptorsSpatialConstant: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
321 :param horizontalCellsGain: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
322 :param HcellsTemporalConstant: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
323 :param HcellsSpatialConstant: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
324 :param ganglionCellsSensitivity: the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.7
327 Retina::RetinaParameters
328 ========================
330 .. ocv:struct:: Retina::RetinaParameters
332 This structure merges all the parameters that can be adjusted threw the **Retina::setup()**, **Retina::setupOPLandIPLParvoChannel** and **Retina::setupIPLMagnoChannel** setup methods
333 Parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel. ::
335 class RetinaParameters{
336 struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters
337 OPLandIplParvoParameters():colorMode(true),
338 normaliseOutput(true), // specifies if (true) output is rescaled between 0 and 255 of not (false)
339 photoreceptorsLocalAdaptationSensitivity(0.7f), // the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
340 photoreceptorsTemporalConstant(0.5f),// the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
341 photoreceptorsSpatialConstant(0.53f),// the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
342 horizontalCellsGain(0.0f),//gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
343 hcellsTemporalConstant(1.f),// the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
344 hcellsSpatialConstant(7.f),//the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
345 ganglionCellsSensitivity(0.7f)//the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.7
347 bool colorMode, normaliseOutput;
348 float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
350 struct IplMagnoParameters{ // Inner Plexiform Layer Magnocellular channel (IplMagno)
351 IplMagnoParameters():
352 normaliseOutput(true), //specifies if (true) output is rescaled between 0 and 255 of not (false)
353 parasolCells_beta(0.f), // the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
354 parasolCells_tau(0.f), //the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
355 parasolCells_k(7.f), //the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
356 amacrinCellsTemporalCutFrequency(1.2f), //the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, typical value is 1.2
357 V0CompressionParameter(0.95f), the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.95
358 localAdaptintegration_tau(0.f), // specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
359 localAdaptintegration_k(7.f) // specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
361 bool normaliseOutput;
362 float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k;
364 struct OPLandIplParvoParameters OPLandIplParvo;
365 struct IplMagnoParameters IplMagno;