如果我有完整的傅里叶图像用于恢复,我如何通过fftw3恢复图像? 我试图将fftwf_complex ** arr1转换为fftwf_complex * arr2并将其放入fftwf_plan_dft_c2r_2d,但输出时出现意外噪音,但不是预期的图像。
int size_s = 1030;
fftwf_complex **ifftshifted - 1030x1030 pixels image
fftwf_complex *result_prefin = fftwf_malloc(size_s * size_s * sizeof(fftwf_complex));
for (int i = 0; i < size_s; i ) {
for (int j = 0; j < size_s; j ) {
result_prefin[j i * size_s][0] = ifftshifted[i][j][0]; //real
result_prefin[j i * size_s][1] = ifftshifted[i][j][1]; //imaginary
}
}
进行逆快速傅里叶变换:
floaf *result_ifft2 = malloc(size_s * size_s * sizeof(float));
fftwf_plan plan = fftwf_plan_dft_c2r_2d(size_s, size_s, result_prefin, result_ifft2, FFTW_ESTIMATE);
fftwf_execute(plan);
fftwf_destroy_plan(plan);
重新创建图像以保存到TIFF:
float size_dim_fft = size_s*size_s;
float **result_ifft2_normal = (d_vector *)malloc(size_s * sizeof(float*));
for (int i = 0, offset = 0; i < size_s; i ) {
result_ifft2_normal[i] = (d_vector)malloc(size_s * sizeof(d_type));
for (int j = 0; j < size_s; j ) {
result_ifft2_normal[i][j] = result_ifft2[j offset]/size_dim_fft;
}
offset = size_s;
}
使用FFTSHIFT,因为频谱已通过IFFTSHIFT进入IFFT功能:
float **result_fftshift = NULL;
shift2d(&result_ifft2_normal, &result_fftshift, 1030, 1030, 0);
write_tiff("restored.tif",result_fftshift,1030,1030);