我们已经编译了KissFFT库,它看起来运行良好,但是我们不确定如何使用它来获取2d图像的频域。 任何帮助都将是极好的。
PS。我们正在After Effects SDK中运行它。
答案 0 :(得分:1)
我尚未将KissFFT
用于图像(仅用于音频),但这是基于我在文档中所读内容的尝试。您应该为各个颜色分量创建3个数组(即,创建img1 / img2 / img3)。
//(I can't test this code now because I don't have kiss_fft)
kiss_fft_scalar img1[M][N]; //array containing red pixels
kiss_fft_scalar img2[M][N]; //array containing green pixels
kiss_fft_scalar img3[M][N];//array containing blue pixels
int mDim[2] = { N, M };
const int numDim = 2; //number of dimensions
kiss_fft_cpx *cinRed = new kiss_fft_cpx[N * M];
kiss_fft_cpx *coutRed = new kiss_fft_cpx[N * M];
kiss_fft_cpx *cinGreen = new kiss_fft_cpx[N * M];
kiss_fft_cpx *coutGreen = new kiss_fft_cpx[N * M];
kiss_fft_cpx *cinBlue = new kiss_fft_cpx[N * M];
kiss_fft_cpx *coutBlue = new kiss_fft_cpx[N * M];
kiss_fftnd_cfg state = kiss_fftnd_alloc (mDim, numDim, 0, 0, 0);
int k=0;
for (int i=0;i<M;++i) {
for(int j=0;j<N;j++){
cinRed[k].r = img1[i][j];
cinRed[k].i = 0;
cinGreen[k].r = img2[i][j];
cinGreen[k].i = 0;
cinBlue[k].r = img3[i][j];
cinBlue[k].i = 0;
k++;
}
}
kiss_fftnd(state,cinRed,coutRed);//coutRed contains 2D fft results for img1 (red channel)
kiss_fftnd(state,cinGreen,coutGreen);
kiss_fftnd(state,cinBlue,coutBlue);
//for inverse 2D FFT just use
state = kiss_fftnd_alloc (mDim, numDim, 1, 0, 0);//1 sets inverse to true
kiss_fftnd(state,coutRed,cinRed); //note that cin and cout have switched positions
kiss_fftnd(state,coutGreen,cinGreen);
kiss_fftnd(state,coutRed,cinGreen);
谢谢克里斯,让我知道我应该使用kiss_fftnd
(我已经删除了旧的代码和过程)