##### Contents

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.

# Script

## 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
```

## DFT of the ROI image

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

```1 import numpy as np
3
4 fd = froi.astype(float)
5 F = np.fft.fft2(fd) # F is the DFT of 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
```

## 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)
```

## 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
4 diff = np.abs(FFx4 - Fx4).sum()             # compare the replicated DFT with DFT of expanded f
5 print 'diff:',diff                          # print the error signal power
```
```diff: 0.0
```

## Comparing in the spatial domain.

```1 ffdx4 = np.fft.ifft2(FFx4)
2 fimag = ffdx4.imag
3 print 'imaginary sum:',fimag.sum()
4 #ffdx4 = np.floor(0.5 + ffdx4.real) # round
```imaginary sum: -4.03896783473e-28