[Numpy-discussion] FFT's & IFFT's on images
Stéfan van der Walt
Wed Jul 2 16:56:03 CDT 2008
2008/7/2 Mike Sarahan <firstname.lastname@example.org>:
> I'm trying to do phase reconstruction on images which involves switching
> back and forth between Fourier space and real space. I'm trying to test
> numpy (& scipy, for that matter) just to see if I can go back and forth.
> After an FFT/iFFT, the resulting image is garbage. I'm using
> numpy.fft.fftn, but I've also tried fft2, rfftn, rfft2, and the
> corresponding inverse FFT's.
> >From looking at the matrices, it appears to be creating complex
> components that aren't in the matrix prior to any FFT's. Real fft's
> seem to add some small component to each value (<1). I'm using
> Image.fromarray to convert arrays to images, and I'm working with 8-bit
> grayscale images.
Those components are very small!
In : x = (np.random.random((15,15)) * 255).astype(np.uint8)
In : np.fft.fft2(x).imag.sum()
And you can see that the forward-reverse transformed values compare
well to the original:
In : z = np.fft.ifft2(np.fft.fft2(x))
In : np.abs(x - z).sum()
If you have bigger problems, send us a code snippet and we'll take a look.
More information about the Numpy-discussion