How it works...

OpenCV uses a fast Fourier transform algorithm (it's implemented by the cv2.dft function) for computing the discrete Fourier transform, and uses the same for its inverse version (the cv2.idft function). The functions support optional flags specifying whether output should be real or complex (flags cv2.DFT_REAL_OUTPUT and cv2.DFT_COMPLEX_OUTPUT, respectively), and whether output values should be scaled (using the cv2.DFT_SCALE flag). The np.fft.fftshift function shifts the frequency spectrum in such a way that the amplitude corresponding to zero frequency becomes located at the center of the array, and it's easier to interpret and work with further.

The following output is expected:

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.