%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
from skimage import data
from skimage import io
from skimage.transform import pyramid_laplacian
The Fourier transform consists of real and imaginary parts
$$ F = F_R + i F_I$$We can analyse the magnitude $|F|$ and the phase of the transform.
def computeMagnitudeSpectrum(image):
F1 = fftpack.fft2(image)
# Now shift the quadrants around so that low spatial frequencies are in
# the center of the 2D fourier transformed image.
F2 = fftpack.fftshift( F1 )
# Calculate a 2D power spectrum
#psd2D = np.abs( F2 )**2
ms = 20*np.abs(F2)
return ms
def computePhaseSpectrum(image):
F1 = fftpack.fft2(image)
# Now shift the quadrants around so that low spatial frequencies are in
# the center of the 2D fourier transformed image.
F2 = fftpack.fftshift( F1 )
# Calculate a 2D power spectrum
#psd2D = np.abs( F2 )**2
ps = np.angle(F2)
return ps
image = io.imread("../images/Lyuba-CT_350.tif")
rows, cols = image.shape
ms = computeMagnitudeSpectrum(image)
ps = computePhaseSpectrum(image)
fig, ax = plt.subplots(figsize=(15, 15))
plt.subplot(1, 3, 1)
plt.imshow(image, cmap='gray')
plt.subplot(1, 3, 2)
plt.imshow(np.log10( ms ))
plt.subplot(1, 3, 3)
plt.imshow(ps, cmap='gray')
plt.show()
image = io.imread("../images/AS_09125.tif")
rows, cols = image.shape
ms = computeMagnitudeSpectrum(image)
ps = computePhaseSpectrum(image)
fig, ax = plt.subplots(figsize=(15, 15))
plt.subplot(1, 3, 1)
plt.imshow(image, cmap='gray')
plt.subplot(1, 3, 2)
plt.imshow(np.log10( ms ))
plt.subplot(1, 3, 3)
plt.imshow(ps, cmap='gray')
plt.show()