# lionisEX09

Autor: lionis 21/05/2009

# Demonstração do filtro no domínio da frequência

## Código de barras

```1 imgBarCode = mmreadgray('Attachments/ia636-2009/exercicio9/barcode.tif')
4
```

## Impressão digital

```1 imgFingerPrint = mmreadgray('db1_a/1_1.tif')
4
```

## Filtros

``` 1 def circleIdealLowPass(filter_size, radius):
2     h,w = filter_size[0],filter_size[1]
3
4     hm = round(float(h)/2)
5     wm = round(float(w)/2)
6
8
11
12     filter = 1 - filter
13
14     return filter
15
16 def squareIdealLowPass(filter_size, square_size):
17     h,w = filter_size[0],filter_size[1]
18
19     filter = zeros((h,w))
20
21     hm = round(float(h)/2)
22     wm = round(float(w)/2)
23     sm = round(float(square_size)/2)
24
25     filter[hm-sm:hm+sm, wm-sm:wm+sm] = 1
26
27     return filter
28
29 def squareIdealHighPass(filter_size, square_size):
30     filter = squareIdealLowPass(filter_size, square_size)
31
32     filter = 1 - filter
33
34     return filter
35
36 def butterworthLowPass(filter_size,D0,n):
37     w,h = filter_size[0], filter_size[1]
38     (u, v) = meshgrid(range(h), range(w))
39     D = sqrt((u-h/2)**2 + (v-w/2)**2)
40
41     return (1 / ( 1 + (D/D0)**(2*n) ))
42
43 def butterworthHighPass(filter_size,D0,n):
44     filter = butterworthLowPass(filter_size,D0,n)
45
46     filter = 1 - filter
47
48     return filter
```
```1 adshow(ianormalize(squareIdealLowPass([200,200], 50),[0,255]),title='Filtro quadrado passa-baixa ideal')
3 adshow(ianormalize(circleIdealLowPass([200,200], 50),[0,255]),title='Filtro circular passa-baixa ideal')
4 adshow(ianormalize(circleIdealHighPass([200,200], 50),[0,255]),title='Filtro circular passa-alta ideal')
```
``` 1 Fv_barcode_lowpass1 = Fv_barcode*squareIdealLowPass(Fv_barcode.shape,75)
2 Fv_barcode_lowpass2 = Fv_barcode*circleIdealLowPass(Fv_barcode.shape,75)
3 Fv_barcode_highpass1 = Fv_barcode*squareIdealHighPass(Fv_barcode.shape,75)
4 Fv_barcode_highpass2 = Fv_barcode*circleIdealHighPass(Fv_barcode.shape,75)
5 Fv_barcode_butterworthLowpass = Fv_barcode*butterworthLowPass(Fv_barcode.shape,50,1)
6 Fv_barcode_butterworthHighpass = Fv_barcode*butterworthHighPass(Fv_barcode.shape,50,1)
7
9 adshow(Fv_barcode_lowpass2,title='Código de barras com filtro passa-baixa circular')
11 adshow(Fv_barcode_highpass2,title='Código de barras com filtro passa-alta circular')
12 adshow(Fv_barcode_butterworthLowpass,title='Código de barras com filtro butterworth passa-baixa')
13 adshow(Fv_barcode_butterworthHighpass,title='Código de barras com filtro butterworth passa-alta')
14
```
``` 1 Fv_fingerprint_lowpass1 = Fv_fingerprint*squareIdealLowPass(Fv_fingerprint.shape,75)
2 Fv_fingerprint_lowpass2 = Fv_fingerprint*circleIdealLowPass(Fv_fingerprint.shape,60)
3 Fv_fingerprint_highpass1 = Fv_fingerprint*squareIdealHighPass(Fv_fingerprint.shape,75)
4 Fv_fingerprint_highpass2 = Fv_fingerprint*circleIdealHighPass(Fv_fingerprint.shape,60)
5 Fv_fingerprint_butterworthLowpass = Fv_fingerprint*butterworthLowPass(Fv_fingerprint.shape,50,1)
6 Fv_fingerprint_butterworthHighpass = Fv_fingerprint*butterworthHighPass(Fv_fingerprint.shape,50,1)
7