Illustrate the scale property of the Discrete Fourier Transform.
The scale property of the Discrete Fourier Transform (DFT) is not the same as in the continuous Fourier Transform. In the discrete case the property is the following. If the image is enlarged in such a way that the new pixels have value zero, then its DFT is filled with a replication of the original DFT. In this demonstration, a small original image is expanded and its DFT is compared to the replicated DFT of the original image. The results should be the same.
Image read, ROI selection and display
The image is read and a small portion (64x64) is selected.
1. f = iaread('cameraman.pgm') 2. froi = f[19:19+64,99:99+64] # ROI selection 3. adshow(f) 4. adshow(froi)
DFT of the ROI image
The DFT of the ROI image is taken and its spectrum is displayed
1. import numpy as np 2. from ia636 import iadftview 3. 4. fd = froi.astype(float) 5. F = np.fft.fft2(fd) # F is the DFT of f 6. adshow(froi) 7. adshow(iadftview(F))
Image expansion (without interpolation) and DFT
The image is expanded by 4, but filling the new pixels with 0
1. fx4 = zeros(4*array(froi.shape)) # size is 4 times larger 2. fx4[::4,::4] = froi # filling the expanded image 3. adshow(froi) 4. adshow(fx4)
DFT of the expansion without interpolation
the resulting DFT is a periodical replication of the original DFT.
1. fdx4 = fx4.astype(float) 2. Fx4 = np.fft.fft2(fdx4) # Fx4 is the DFT of fx4 (expanded f) 3. adshow(iadftview(F)) 4. adshow(iadftview(Fx4))
Comparing in the frequency domain.
Alternatively, the original DFT (F) is replicated by 4 in each direction and compared with the DFT of the expanded image. For quantitative comparison, both the sum of the absolute errors of all pixels is computed and displayed.
1. aux = np.concatenate((F,F,F,F)) 2. FFx4 = np.concatenate((aux,aux,aux,aux), 1) # replicate the DFT of f 3. adshow(iadftview(FFx4)) 4. diff = abs(FFx4 - Fx4).sum() # compare the replicated DFT with DFT of expanded f 5. print diff # print the error signal power
Comparing in the spatial domain.
1. ffdx4 = np.fft.ifft2(FFx4) 2. fimag = ffdx4.imag 3. print fimag.sum() 4. ffdx4 = floor(0.5 + ffdx4.real) # round 5. adshow(ffdx4.astype(int32)) 6. error = abs(fdx4 - ffdx4).sum() 7. print error