[英]Translating from Matlab to C a function
I am translating a funciton from Matlab to C. I have a problem with just some lines with Fourier Transform. 我正在将功能从Matlab转换为C。仅对Fourier Transform的某些行有问题。 This is the code, the commented lines are in Matlab and That's what I need to translate.
这是代码,注释行在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;
}
或者,如果您想对FFT进行编码,请查看MATLABS的fft代码并逐行转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.