Commit c8e206c2 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

added LogPolar Blind Spot Model (thanks to Fabio Solari for the contribution)

parent d1061677
......@@ -44,6 +44,7 @@
#define __OPENCV_CONTRIB_HPP__
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
......@@ -633,14 +634,219 @@ namespace cv
TRANSLATION = 2,
RIGID_BODY_MOTION = 4
};
CV_EXPORTS bool RGBDOdometry( cv::Mat& Rt, const Mat& initRt,
const cv::Mat& image0, const cv::Mat& depth0, const cv::Mat& mask0,
const cv::Mat& image1, const cv::Mat& depth1, const cv::Mat& mask1,
const cv::Mat& cameraMatrix, float minDepth, float maxDepth, float maxDepthDiff,
CV_EXPORTS bool RGBDOdometry( Mat& Rt, const Mat& initRt,
const Mat& image0, const Mat& depth0, const Mat& mask0,
const Mat& image1, const Mat& depth1, const Mat& mask1,
const Mat& cameraMatrix, float minDepth, float maxDepth, float maxDepthDiff,
const std::vector<int>& iterCounts, const std::vector<float>& minGradientMagnitudes,
int transformType=RIGID_BODY_MOTION );
/**
*Bilinear interpolation technique.
*
*The value of a desired cortical pixel is obtained through a bilinear interpolation of the values
*of the four nearest neighbouring Cartesian pixels to the center of the RF.
*The same principle is applied to the inverse transformation.
*
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
*/
class CV_EXPORTS LogPolar_Interp
{
public:
LogPolar_Interp() {}
/**
*Constructor
*\param w the width of the input image
*\param h the height of the input image
*\param center the transformation center: where the output precision is maximal
*\param R the number of rings of the cortical image (default value 70 pixel)
*\param ro0 the radius of the blind spot (default value 3 pixel)
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
* \a 0 means that the retinal image is computed within the inscribed circle.
*\param S the number of sectors of the cortical image (default value 70 pixel).
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
* \a 0 means that the parameter \a S is provided by the user.
*/
LogPolar_Interp(int w, int h, Point2i center, int R=70, double ro0=3.0,
int interp=INTER_LINEAR, int full=1, int S=117, int sp=1);
/**
*Transformation from Cartesian image to cortical (log-polar) image.
*\param source the Cartesian image
*\return the transformed image (cortical image)
*/
const Mat to_cortical(const Mat &source);
/**
*Transformation from cortical image to retinal (inverse log-polar) image.
*\param source the cortical image
*\return the transformed image (retinal image)
*/
const Mat to_cartesian(const Mat &source);
/**
*Destructor
*/
~LogPolar_Interp();
protected:
Mat Rsri;
Mat Csri;
int S, R, M, N;
int top, bottom,left,right;
double ro0, romax, a, q;
int interp;
Mat ETAyx;
Mat CSIyx;
void create_map(int M, int N, int R, int S, double ro0);
};
/**
*Overlapping circular receptive fields technique
*
*The Cartesian plane is divided in two regions: the fovea and the periphery.
*The fovea (oversampling) is handled by using the bilinear interpolation technique described above, whereas in
*the periphery we use the overlapping Gaussian circular RFs.
*
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
*/
class CV_EXPORTS LogPolar_Overlapping
{
public:
LogPolar_Overlapping() {}
/**
*Constructor
*\param w the width of the input image
*\param h the height of the input image
*\param center the transformation center: where the output precision is maximal
*\param R the number of rings of the cortical image (default value 70 pixel)
*\param ro0 the radius of the blind spot (default value 3 pixel)
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
* \a 0 means that the retinal image is computed within the inscribed circle.
*\param S the number of sectors of the cortical image (default value 70 pixel).
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
* \a 0 means that the parameter \a S is provided by the user.
*/
LogPolar_Overlapping(int w, int h, Point2i center, int R=70,
double ro0=3.0, int full=1, int S=117, int sp=1);
/**
*Transformation from Cartesian image to cortical (log-polar) image.
*\param source the Cartesian image
*\return the transformed image (cortical image)
*/
const Mat to_cortical(const Mat &source);
/**
*Transformation from cortical image to retinal (inverse log-polar) image.
*\param source the cortical image
*\return the transformed image (retinal image)
*/
const Mat to_cartesian(const Mat &source);
/**
*Destructor
*/
~LogPolar_Overlapping();
protected:
Mat Rsri;
Mat Csri;
vector<int> Rsr;
vector<int> Csr;
vector<double> Wsr;
int S, R, M, N, ind1;
int top, bottom,left,right;
double ro0, romax, a, q;
struct kernel
{
kernel() { w = 0; }
vector<double> weights;
int w;
};
Mat ETAyx;
Mat CSIyx;
vector<kernel> w_ker_2D;
void create_map(int M, int N, int R, int S, double ro0);
};
/**
* Adjacent receptive fields technique
*
*All the Cartesian pixels, whose coordinates in the cortical domain share the same integer part, are assigned to the same RF.
*The precision of the boundaries of the RF can be improved by breaking each pixel into subpixels and assigning each of them to the correct RF.
*This technique is implemented from: Traver, V., Pla, F.: Log-polar mapping template design: From task-level requirements
*to geometry parameters. Image Vision Comput. 26(10) (2008) 1354-1370
*
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
*/
class CV_EXPORTS LogPolar_Adjacent
{
public:
LogPolar_Adjacent() {}
/**
*Constructor
*\param w the width of the input image
*\param h the height of the input image
*\param center the transformation center: where the output precision is maximal
*\param R the number of rings of the cortical image (default value 70 pixel)
*\param ro0 the radius of the blind spot (default value 3 pixel)
*\param smin the size of the subpixel (default value 0.25 pixel)
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
* \a 0 means that the retinal image is computed within the inscribed circle.
*\param S the number of sectors of the cortical image (default value 70 pixel).
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
* \a 0 means that the parameter \a S is provided by the user.
*/
LogPolar_Adjacent(int w, int h, Point2i center, int R=70, double ro0=3.0, double smin=0.25, int full=1, int S=117, int sp=1);
/**
*Transformation from Cartesian image to cortical (log-polar) image.
*\param source the Cartesian image
*\return the transformed image (cortical image)
*/
const Mat to_cortical(const Mat &source);
/**
*Transformation from cortical image to retinal (inverse log-polar) image.
*\param source the cortical image
*\return the transformed image (retinal image)
*/
const Mat to_cartesian(const Mat &source);
/**
*Destructor
*/
~LogPolar_Adjacent();
protected:
struct pixel
{
pixel() { u = v = 0; a = 0.; }
int u;
int v;
double a;
};
int S, R, M, N;
int top, bottom,left,right;
double ro0, romax, a, q;
vector<vector<pixel> > L;
vector<double> A;
void subdivide_recursively(double x, double y, int i, int j, double length, double smin);
bool get_uv(double x, double y, int&u, int&v);
void create_map(int M, int N, int R, int S, double ro0, double smin);
};
}
#include "opencv2/contrib/retina.hpp"
#endif
......
This diff is collapsed.
/*Authors
* Manuela Chessa, Fabio Solari, Fabio Tatti, Silvio P. Sabatini
*
* manuela.chessa@unige.it, fabio.solari@unige.it
*
* PSPC-lab - University of Genoa
*/
#include "opencv2/opencv.hpp"
#include <iostream>
#include <cmath>
using namespace cv;
using namespace std;
void help()
{
cout << "LogPolar Blind Spot Model sample.\nShortcuts:"
"\n\tn for nearest pixel technique"
"\n\tb for bilinear interpolation technique"
"\n\to for overlapping circular receptive fields"
"\n\ta for adjacent receptive fields"
"\n\tq or ESC quit\n";
}
int main(int argc, char** argv)
{
Mat img = imread(argc > 1 ? argv[1] : "lena.jpg",1); // open the image
if(img.empty()) // check if we succeeded
{
cout << "can not load image\n";
return 0;
}
help();
Size s=img.size();
int w=s.width, h=s.height;
int ro0=3; //radius of the blind spot
int R=120; //number of rings
//Creation of the four different objects that implement the four log-polar transformations
//Off-line computation
Point2i center(w/2,h/2);
LogPolar_Interp nearest(w, h, center, R, ro0, INTER_NEAREST);
LogPolar_Interp bilin(w,h, center,R,ro0);
LogPolar_Overlapping overlap(w,h,center,R,ro0);
LogPolar_Adjacent adj(w,h,center,R,ro0,0.25);
namedWindow("Cartesian",1);
namedWindow("retinal",1);
namedWindow("cortical",1);
int wk='n';
Mat Cortical, Retinal;
//On-line computation
for(;;)
{
if(wk=='n'){
Cortical=nearest.to_cortical(img);
Retinal=nearest.to_cartesian(Cortical);
}else if (wk=='b'){
Cortical=bilin.to_cortical(img);
Retinal=bilin.to_cartesian(Cortical);
}else if (wk=='o'){
Cortical=overlap.to_cortical(img);
Retinal=overlap.to_cartesian(Cortical);
}else if (wk=='a'){
Cortical=adj.to_cortical(img);
Retinal=adj.to_cartesian(Cortical);
}
imshow("Cartesian", img);
imshow("cortical", Cortical);
imshow("retinal", Retinal);
int c=waitKey(15);
if (c>0) wk=c;
if(wk =='q' || (wk & 255) == 27) break;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment