[iadftmatrixexamples] [Up] [iaconvteo] Lessons

iadftscaleproperty
Illustrate the scale property of the Discrete Fourier Transform.

Description

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.

Equation

Demo Script

Image read, ROI selection and display

The image is read and a small portion (64x64) is selected.

>>> f = iaread('cameraman.pgm')

                  
>>> froi = f[19:19+64,99:99+64] # ROI selection

                  
>>> iashow(f)
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
>>> iashow(froi)
(64, 64) Min= 1 Max= 251 Mean=128.306 Std=93.47
f froi

DFT of the ROI image

The DFT of the ROI image is taken and its spectrum is displayed

>>> import Numeric, FFT

                  
>>> fd = froi.astype(Numeric.Float)

                  
>>> F = FFT.fft2d(fd) # F is the DFT of f

                  
>>> iashow(froi)
(64, 64) Min= 1 Max= 251 Mean=128.306 Std=93.47
>>> iashow(iadftview(F))
(64, 64) Min= 63 Max= 255 Mean=144.058 Std=19.28
froi iadftview(F)

Image expansion (without interpolation) and DFT

The image is expanded by 4, but filling the new pixels with 0

>>> fx4 = Numeric.zeros(4*Numeric.array(froi.shape)) # size is 4 times larger

                  
>>> fx4[::4,::4] = froi                              # filling the expanded image

                  
>>> iashow(froi)
(64, 64) Min= 1 Max= 251 Mean=128.306 Std=93.47
>>> iashow(fx4)
(256, 256) Min= 0 Max= 251 Mean=8.019 Std=38.87
froi fx4

DFT of the expansion without interpolation

the resulting DFT is a periodical replication of the original DFT.

>>> fdx4 = fx4.astype(Numeric.Float)

                  
>>> Fx4 = FFT.fft2d(fdx4) # Fx4 is the DFT of fx4 (expanded f)

                  
>>> iashow(iadftview(F))
(64, 64) Min= 63 Max= 255 Mean=144.058 Std=19.28
>>> iashow(iadftview(Fx4))
(256, 256) Min= 63 Max= 255 Mean=144.058 Std=19.28
iadftview(F) 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.

>>> aux = Numeric.concatenate((F,F,F,F))

                  
>>> FFx4 = Numeric.concatenate((aux,aux,aux,aux), 1) # replicate the DFT of f

                  
>>> iashow(iadftview(FFx4))
(256, 256) Min= 63 Max= 255 Mean=144.058 Std=19.28
>>> diff = abs(FFx4 - Fx4)                           # compare the replicated DFT with DFT of expanded f

                  
>>> print Numeric.sum(Numeric.ravel(diff))           # print the error signal power
0.0
iadftview(FFx4)

Comparing in the spatial domain.

>>> ffdx4 = FFT.inverse_fft2d(FFx4)

                  
>>> fimag = ffdx4.imag

                  
>>> print Numeric.sum(Numeric.ravel(fimag))
7.19441145562e-028
>>> ffdx4 = Numeric.floor(0.5 + ffdx4.real) # round

                  
>>> iashow(ffdx4.astype(Numeric.Int))
(256, 256) Min= 0 Max= 251 Mean=8.019 Std=38.87
>>> error = abs(fdx4 - ffdx4)

                  
>>> print Numeric.sum(Numeric.ravel(error))
0.0
ffdx4.astype(Numeric.Int)

[iadftmatrixexamples] [Up] [iaconvteo] http://www.python.org