Pre-compute some stuff to speed up filter construction with OpenCV [closed]

asked 2013-06-26 07:02:54 -0500

residentelvio gravatar image

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
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;
radius = radius + epsilon;

% 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++)

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

    radius =(double**)malloc(sizeof(double*)*rows);
          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++){

  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];
              radius[a][b] = sqrt(X[a][b]);

  for(int a=0;a<rows;a++){
       for(int b=0;b<cols;b++){
           radius [a][b]= radius[a][b] + epsilon;
           theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;


edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by SR
close date 2013-06-30 15:43:03.513021