How I can restore image by means of fftw3 if I have full fourier spectrum of image for restoring? I have tried to transmute fftwf_complex **arr1 to fftwf_complex *arr2 and put it into the fftwf_plan_dft_c2r_2d, but on output was a unexpected noise but not the expected image.
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
}
}
Make a inverse fast fourier transform:
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);
Recreating the image for saving to 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;
}
Use FFTSHIFT because the spectrum was put into the IFFT function with IFFTSHIFT:
float **result_fftshift = NULL;
shift2d(&result_ifft2_normal, &result_fftshift, 1030, 1030, 0);
write_tiff("restored.tif",result_fftshift,1030,1030);