[iadftdecompose] [Up] [iadftmatrixexamples] Lessons

iadftexamples
Demonstrate the DFT spectrum of simple synthetic images.

Demo Script

Constant image

The DFT of a constant image is a single point at F(0,0), which gives the sum of all pixels in the image.

>>> import Numeric, FFT

                  
>>> f = 50 * Numeric.ones((10, 20))

                  
>>> F = FFT.fft2d(f)

                  
>>> aux = F.real > 1E-5

                  
>>> r, c = iaind2sub([10, 20], Numeric.nonzero(Numeric.ravel(aux)))

                  
>>> print r
[0]
>>> print c
[0]
>>> print F[r[0],c[0]]/(10.*20.)
(50+0j)

Square

The DFT of a square image is a digital sync.

>>> f = Numeric.zeros((128, 128))

                  
>>> f[63:63+5,63:63+5] = 1

                  
>>> iashow(f)
(128, 128) Min= 0 Max= 1 Mean=0.002 Std=0.04
>>> F = FFT.fft2d(f)

                  
>>> Fv = iadftview(F)

                  
>>> iashow(Fv)
(128, 128) Min= 0 Max= 255 Mean=73.791 Std=59.51
f Fv

Pyramid

The DFT of a pyramid is the square of the digital sync.

>>> f = Numeric.zeros((128, 128))

                  
>>> k = Numeric.array([[1,2,3,4,5,6,5,4,3,2,1]])

                  
>>> k2 = Numeric.matrixmultiply(Numeric.transpose(k), k)

                  
>>> f[63:63+k2.shape[0], 63:63+k2.shape[1]] = k2

                  
>>> iashow(f)
(128, 128) Min= 0 Max= 36 Mean=0.079 Std=1.14
>>> F = FFT.fft2d(f)

                  
>>> Fv = iadftview(F)

                  
>>> iashow(Fv)
(128, 128) Min= 0 Max= 255 Mean=51.718 Std=59.31
f Fv

Gaussian

The DFT of a Gaussian image is a Gaussian image.

>>> f = iagaussian([128,128],[65,65],[[3*3,0],[0,5*5]])

                  
>>> fn = ianormalize(f,[0,255])

                  
>>> iashow(fn)
(128, 128) Min= 0.0 Max= 255.0 Mean=1.467 Std=13.60
>>> F = FFT.fft2d(f)

                  
>>> Fv = iadftview(F)

                  
>>> iashow(Fv)
(128, 128) Min= 0 Max= 255 Mean=3.168 Std=20.45
fn Fv

Impulse

The DFT of an impulse image is an impulse image.

>>> f = iacomb((128,128), (4,4), (0,0))

                  
>>> fn = ianormalize(f, (0,255))

                  
>>> iashow(fn)
(128, 128) Min= 0.0 Max= 255.0 Mean=15.938 Std=61.73
>>> F = FFT.fft2d(f)

                  
>>> Fv = iadftview(F)

                  
>>> iashow(Fv)
(128, 128) Min= 0 Max= 255 Mean=0.249 Std=7.97
fn Fv

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