# Revision history [back]

### Pre-compute some stuff to speed up filter construction with OpenCV

Hi to all , I have a bug in this function because running my work it doesn' go out from a function. That' s the original Matlab code:

function [radius, theta]=pre_filter_Computations(cols,rows)

x = (-cols/2 : (cols/2 - 1))/(cols/2);
y = -(-rows/2 : (rows/2 - 1))/(rows/2);
[x,y] = meshgrid(x,y);

radius = sqrt(x.^2 + y.^2); % Matrix values contain radius from centre.
radius(floor(rows/2+1),floor(cols/2+1)) = 1; % Get rid of the 0 radius value at the 0
% frequency point (now at top-left corner)
% so that taking the log of the radius will
% not cause trouble.
epsilon = 0.0001;

% angle
theta = atan2(y,x); % Matrix values contain polar angle.


What I did in C/C++... In the main:

double **radius,**theta,**filter;

filter =(double**)malloc(sizeof(double*)*rows);
for(int x=0;x<rows;x++)
filter[x]=(double*)malloc(sizeof(double)*cols);

theta =(double**)malloc(sizeof(double*)*rows);
for(int y= 0;y<cols;y++)
theta[y]=(double*)malloc(sizeof(double)*cols);

for(int z=0;z<cols;z++)



In the function:

 void pre_filter_Computations(double **radius,double **theta,int cols,int rows){

double x[cols],y[rows];
double X[cols][rows], Y[cols][rows];
double epsilon=0.0001;

for(int j=0;j<cols;j++){
for(int i=-(cols/2);i<=(cols/2)-1;i++){
x[j]= i/(cols/2);
}
}
for(int k=0;k<rows;k++){
for(int z=-(rows/2);z<=(rows/2)-1;z++){
y[k]= -z/(rows/2);
}
}

for(int i=0;i<cols;i++){
for(int z=0;z<rows;z++){
X[i][z]=x[i];
Y[i][z]=y[z];
}
}

for(int a=0;a<rows;a++){
for(int b=0;b<cols;b++){

X[a][b] = pow(X[a][b],2);
Y[a][b] = pow(Y[a][b],2);
X[a][b] = X[a][b] + Y[a][b];
}
}