Function iafftshift

Synopse

Shifts zero-frequency component to center of spectrum.

  • g = iafftshift(f)
    • OUTPUT
      • g: Image.
    • INPUT
      • f: Image. n-dimensional.

Description

The origin (0,0) of the DFT is normally at top-left corner of the image. For visualization purposes, it is common to periodically translate the origin to the image center. This is particularly interesting because of the complex conjugate symmetry of the DFT of a real function. Note that as the image can have even or odd sizes, to translate back the DFT from the center to the corner, there is another correspondent function: iaifftshift.

1 import numpy as np
2 
3 def iafftshift(f):
4     from ia636 import iaptrans
5 
6     f = np.asarray(f)
7 
8     return iaptrans(f, np.array(f.shape)/2)

Examples

Numerical 1D Example

Odd dimension

1 import numpy as np
2 import ia636 as ia
3 
4 F = np.arange(5)
5 Fs = ia.iafftshift(F)
6 print 'F=\n',F
7 print 'Fs=\n',Fs
F=
[0 1 2 3 4]
Fs=
[3 4 0 1 2]

Even dimension

1 F = np.arange(6)
2 Fs = ia.iafftshift(F)
3 print 'F=\n',F
4 print 'Fs=\n',Fs
F=
[0 1 2 3 4 5]
Fs=
[3 4 5 0 1 2]

Numerical complex example

1 F = array([[10+0j,20+5j,20-5j],
2            [40+3j,60+2j,70+4j],
3            [30+0j,50+2j,50-2j],
4            [40-3j,70-4j,60-2j]])
5 Fs = ia.iafftshift(F)
6 print 'F=\n',F
7 print 'Fs=\n',Fs
F=
[[ 10.+0.j  20.+5.j  20.-5.j]
 [ 40.+3.j  60.+2.j  70.+4.j]
 [ 30.+0.j  50.+2.j  50.-2.j]
 [ 40.-3.j  70.-4.j  60.-2.j]]
Fs=
[[ 50.-2.j  30.+0.j  50.+2.j]
 [ 60.-2.j  40.-3.j  70.-4.j]
 [ 20.-5.j  10.+0.j  20.+5.j]
 [ 70.+4.j  40.+3.j  60.+2.j]]

Image

1 import ia636 as ia
2 
3 f = ia.iarectangle([120,150],[7,10],[60,75])
4 F = ia.iadft(f)
5 Fs = ia.iafftshift(F)
6 adshow(ia.iadftview(F))
7 adshow(ia.iadftview(Fs))

Equation

See Also

Contributions

  • André Luis da Costa, 1st semester 2011