# Synopse

Discrete 1D/2D/3D Fourier Transform.

• F = iadft(f)
• F: Output Image.
• f: Original Image.

# Function Code

``` 1 from numpy import *
2
4     from ia636 import iadftmatrix
5     f = asarray(f).astype(float64)
6     if (len(f.shape) == 1):
7         m = len(f)
8         A = iadftmatrix(f.shape[0])
9         F = sqrt(m) * dot(A, f)
10     elif (len(f.shape) == 2):
11         (m, n) = f.shape
12         A = iadftmatrix(m)
13         B = iadftmatrix(n)
14         F = sqrt(m * n) * dot(dot(A, f), B)
15     else:
16         (p,m,n) = f.shape
17         A = iadftmatrix(m)
18         B = iadftmatrix(n)
19         C = iadftmatrix(p)
20         Faux = dot(A,f)
21         Faux = dot(Faux,B)
22         F = sqrt(p)*sqrt(m)*sqrt(n)*dot(C,Faux)
23     return F
```

# Examples

## Numeric Example: comparing proposed with numpy function

``` 1 from ia636 import *
2 from numpy import *
3
4 f = arange(24).reshape(2,3,4) # original image with generic axis
5 F = iadft(f)   # proposed dft
6 F1 = fft.fftn(f) # numpy dft
7
9 print 'fft.fftn:','\n',F1.round(2),'\n'
10 print 'Equal Results? (max error)',abs(F1-F).max()
```
```ia636.iadft:
[[[ 276. +0.j    -12.+12.j    -12. -0.j    -12.-12.j  ]
[ -48.+27.71j    0. +0.j      0. +0.j     -0. +0.j  ]
[ -48.-27.71j    0. +0.j     -0. +0.j     -0. +0.j  ]]

[[-144. -0.j      0. +0.j     -0. +0.j     -0. +0.j  ]
[   0. +0.j     -0. +0.j     -0. -0.j     -0. +0.j  ]
[  -0. +0.j      0. -0.j     -0. -0.j     -0. -0.j  ]]]

fft.fftn:
[[[ 276. +0.j    -12.+12.j    -12. +0.j    -12.-12.j  ]
[ -48.+27.71j    0. +0.j      0. +0.j      0. +0.j  ]
[ -48.-27.71j    0. +0.j      0. +0.j      0. +0.j  ]]

[[-144. +0.j      0. +0.j      0. +0.j      0. +0.j  ]
[   0. +0.j      0. +0.j      0. +0.j      0. +0.j  ]
[   0. +0.j      0. +0.j      0. +0.j      0. +0.j  ]]]

Equal Results? (max error) 8.10143365796e-14
```

## Image example: 2d circle

```1 from ia636 import *
2 from numpy import *
3
4 f = 255 * iacircle([256,256], 10, [129,129])
6 F = iadft(f)
7 Fv = iadftview(F)
```

## Image example: 3d square

```1 from ia636 import *
2
3 f = zeros((25,30,40))
4 f[10:15,20:26,21:27] = 1
5 F = iadft(f)
```

# Comparison with other implementations

``` 1 import numpy as np
2 import time
3 import ia636 as ia
4
6 t = time.time()
7 F1 = ia.iadft(f)
8 t1 = time.time() - t
9 t = time.time()
10 F2 = np.fft.fft2(f)
11 t2 = time.time() - t
12 print 'Max difference is:', np.abs(F1-F2).max()
13 print 'iadft: %d ms' % (int(t1*1000),)
14 print 'fft2: %d ms' % (int(t2*1000),)
```
```Max difference is: 4.96503495159e-06
fft2: 4 ms
```