使用 KissFFT 获取频域图像并返回
Using KissFFT to get frequency domain image and back
我们编译了 KissFFT 库,它看起来 运行 不错,但我们不确定如何使用它来获取 2d 图像的频域。
任何帮助都会很棒。
PS。我们在 After Effects SDK 中 运行 它。
我还没有将 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);
谢谢 Cris 让我知道我应该使用 kiss_fftnd
(我已经删除了旧代码和程序)
我们编译了 KissFFT 库,它看起来 运行 不错,但我们不确定如何使用它来获取 2d 图像的频域。 任何帮助都会很棒。
PS。我们在 After Effects SDK 中 运行 它。
我还没有将 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);
谢谢 Cris 让我知道我应该使用 kiss_fftnd
(我已经删除了旧代码和程序)