# DECONVOLUÇÃO

``` 1 img =adreadgray('cameraman.tif')
2 #Scale
3 T1 = array([[0.97,0,0],[0,0.97,0],[0,0,1]], 'd')
4 #Translate
5 T2 = array([[1,0,4],[0,1,2],[0,0,1]], 'd')
6 f1 = iaffineT(img,T1); #scale
7 f2 = iaffineT(f1,T2); #traslate
8 f=f1+f2 # formação da imagem com eco
9 iashow(uint16(ianormalize(f, [0,255])),title = 'imagem de video deslocado no tempo ou imagen com eco')
12 h = zeros([256,256],'d')
13 h[127,126]=1;
14 h[129,130]=1;
15 iashow(h,title = 'h - máscara de convolução associada a esta deformação conhecida')
17 iashow(uint16(ianormalize(iadftview(H), [0,255])),title = 'H - DFT da mascara')
18 G=F/H;
19 iashow(uint16(ianormalize(iadftview(G), [0,255])),title = 'G = F/H - DFT da imagem melhorada')
20 D1=abs(iaidft(F/H))
21 iashow(uint16(ianormalize(iaifftshift(D1), [0,255])),title = 'g Imagem melhorada')
```
```Warning: downcasting image from double to uint16 (may lose precision)
```

# Testeando iagaussiana

## iagaussian do Toolbox ia636

```1 f = iagaussian((100,100), transpose([[45,50]]), [[20,5],[5,10]]) > 0.0000001
2 #g = ianormalize(f, [0,255]).astype(uint8)
3 iashow(f)
```

## iagauusiana do exercicio 13

``` 1 from numpy.linalg import *
2
3 def iagaussian2(s, mu, sigma):
4     s, mu, sigma = asarray(s), asarray(mu), asarray(sigma)
5     n = s.size # n: dimensão
6
7     if (n == 1):  # 1-D case
8         x = arange(s)
9         d = x - mu
10         k = (1. * d * d) /sigma
11
12     else:         # n-D case
13         # the lines below generates the coordinate matrix for the dimension "n" provided in s
14         n = s.size
15         x = zeros((prod(s),n))
16         x[:,n-1] = arange(prod(s))
17         for i in range(1,n):
18             aux=x[:,n-i]
19             x[:,n-i-1],x[:,n-i]=iaind2sub([s[n-i-1],s[n-i]],aux)
20         x=x.astype(uint8)
21         #
22         d = x - resize(reshape(mu,(mu.size,1)), (prod(s),mu.size))
23
24         if sigma.size == 1:
25             tmp = 1./sigma
26         else:
27             tmp = inv(sigma)
28
29         k = dot(d, tmp) * d
30         k = sum(k,axis=1)
31
32     g = zeros(s, float)
33     aux = ravel(g)
34     if sigma.size == 1:
35         tmp = sigma
36     else:
37         tmp = det(sigma)
38     aux[:] = 1./(2*pi*sqrt(tmp)) * exp(-1./2 * k)
39     return g
```
```1 f = iagaussian2([100,100], [45,50], [[20,5],[5,10]]) > 0.0000001
2 #g = ianormalize(f, [0,255]).astype(uint8)
3 iashow(f)
```