从Matlab转换为C函数

时间:2013-05-18 20:30:04

标签: c matlab opencv fft

我正在将一个函数从Matlab转换为C.我只有一些使用傅里叶变换的行存在问题。这是代码,注释行在Matlab中,这就是我需要翻译的内容。

   Mat logGabor(Mat imfft,int *sz2filt_r,int *sz2filt_c,double r_o, double theta_o,double sigma_theta,double **radius,double **theta,int cols,int rows,double sigma_r,int *padSize);
     Mat rpad;
     int k=*padSize;
     int rs=*sz2filt_r;
     int cs=*sz2filt_c;
   double x[rs-(2*k)],y[cs-(2*k)],sintheta[rows][cols],costheta[rows][cols];
   double ds[rows][cols],dc[rows][cols],divis[rows][cols],divis2[rows][cols];

   double filter[rows][cols],dalpha[rows][cols],spread[rows][cols];
   double div=(PI)/180.0;

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

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

  theta[a][b]=theta[a][b]*div;

  sintheta[a][b]=sin(theta[a][b]);

  costheta[a][b]=cos(theta[a][b]);

  ds[a][b] = (sintheta[a][b] * cos(theta_o) - costheta[a][b] * sin(theta_o))*div;
  dc[a][b] = (costheta[a][b] * cos(theta_o) + sintheta[a][b] * sin(theta_o))*div;
  dalpha[a][b] = abs(atan2(ds[a][b],dc[a][b]));
  divis[a][b] = -(dalpha[a][b]*dalpha[a][b])/(2*(sigma_theta*sigma_theta));
  spread[a][b]= exp(divis[a][b]);
  divis2[a][b]= -(log((radius[a][b]/r_o) * (radius[a][b]/r_o))/(2*log(sigma_r*sigma_r)));
  filter[a][b]= exp(divis2[a][b]);
  filter[a][b]=filter[a][b]*spread[a][b];
  //  filter = fftshift(filter);

  //  rpad = ifft2(imfft.*filter);
  }
      }

 for(int i=1+k;i<=rs-k;i++)
    x[i]= i;

 for(int i=1+k;i<=cs-k;i++)
      y[i]= i;

  //  rpad=rpad(x,y);  delete x & y from rpad

    return rpad;
    }

1 个答案:

答案 0 :(得分:-3)

或者如果您想自己编写FFT,请查看MATLAB的fft代码并逐行进行翻译。