38
BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change the facts. ~Einstein

Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

BLM429 Görüntü İşlemeye Giriş

Dr. Öğr. Üyesi Caner ÖZCAN

Bölüm 5 Uzamsal Filtreleme

If the facts don't fit the theory, change the facts. ~Einstein

Page 2: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

İçerik

2

3. Yeğinlik Dönüşümleri ve Uzamsal Filtreleme

►Temel Bazı Yeğinlik Dönüşüm Fonksiyonları

►Histogram İşleme

►Uzamsal Filtrelemenin Esasları

►Uzamsal Yumuşatma Filtreleri

►Uzamsal Keskinleştirme Filtreleri

►Uzamsal Zenginleştirme Yöntemlerini Birleştirme

►Yeğinlik Dönüşümleri ve Uzamsal Filtreleme İçin Bulanık Tekniklerin Kullanılması

Page 3: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Komşuluk Önemi

3

►Hem zebralarda hem de dalmaçyalılarda benzer sayılarda siyah ve beyaz pikseller vardır.

► İkisi arasındaki fark, tek piksel değerleri yerine küçük grup piksellerin karakteristik görünümüdür.

Page 4: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme

4

►Uzamsal bir filtre (a) bir komşuluk bölgesinden ve (b) bir ön tanımlı işlemden oluşmaktadır.

►MxN’lik bir görüntünün mxn’lik bir filtre ile doğrusal uzamsal filtrelenmesi şu şekilde ifade edilir: ( , ) ( , ) ( , )

a b

s a t b

g x y w s t f x s y t

Page 5: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme

5

Page 6: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

6 Slide credit: S. Seitz

Page 7: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

7 Slide credit: S. Seitz

Page 8: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

8 Slide credit: S. Seitz

Page 9: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

9 Slide credit: S. Seitz

Page 10: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

10 Slide credit: S. Seitz

Page 11: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Filtreleme (2B Hareketli Ortalama)

11 Slide credit: S. Seitz

Page 12: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Yumuşatma Filtreleri

12

►Yumuşatma filtreleri, bulanıklaştırma ve gürültü azaltma amacıyla kullanılmaktadır.

►Bulanıklaştırma, görüntüdeki küçük detayların ortadan kaldırılması ve doğrular veya eğrilerdeki küçük boşlukların bağlanmasında kullanılır.

►Doğrusal ve doğrusal olmayan filtreleri içerir.

Page 13: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

İki Yumuşatma (Ortalama Alma) Filtresi Maskesi

13

Matlab Kodu:

H= ones(3)/9;

result = filter2(H,image);

ya da

result = conv2(image, ones(3)/9);

Page 14: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

İki Yumuşatma (Ortalama Alma) Filtresi Maskesi

14

clc clear all img=double(imread('cameraman.tif')); imshow(uint8(img)) [m n]=size(img); w = ones(3) for i=0:m-3 for j=0:n-3 sum=0; for k=1:3 for l=1:3 sum = sum + img(i+k,j+l)*w(k,l); end end img1(i+1,j+1) = sum/9; end end img2 = uint8(img1); figure imshow(img2) %imwrite(img2,‘output.png','png');

Page 15: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

İki Yumuşatma (Ortalama Alma) Filtresi Maskesi

15

clc clear all img=(imread('cameraman.tif')); imshow(img) %img2=uint8(img); w=(ones(3,3))/9; %w(2,2)=1; img2 = uint8(imfilter(img,w)); %imwrite(img2,'deneme_alcak_g.png','png'); figure imshow(img2)

Page 16: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Doğrusal Yumuşatma Filtreleri

16

The general implementation for filtering an M N image

with a weighted averaging filter of size m n is given

( , ) ( , )

( , )

( , )

where 2 1

a b

s a t b

a b

s a t b

w s t f x s y t

g x y

w s t

m a

, 2 1.n b

MxN’lik bir görüntünün mxn’lik bir ağırlıklı ortalama

alma filtresi ile filtrelenmesi işlemi şu ifade ile verilir:

burada

Page 17: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

17

Doğrusal Yumuşatma Filtreleri

Page 18: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

18

Örnek: Nesnelerin Kaba Temsili

Page 19: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Sıra İstatistiği (Doğrusal Olmayan) Filtreler

19

— Doğrusal olmayan filtrelerdir.

— Süzgeç tarafından çevrelenen görüntü bölgesindeki piksellerin sıralanması ve sonra da merkezdeki piksel değerinin bu sıralama sonucuyla tespit edilen değerle değiştirilmesidir.

Örneğin medyan filtre, max filtre, min filtre

Page 20: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Sıra İstatistiği (Doğrusal Olmayan) Filtreler

20

clc clear all img=double(imread('glassware_noisy.png','png')); [m n]=size(img); p=3; for i=1:m-p for j=1:n-p w=img(i:i+p-1,j:j+p-1); img2(i,j) = median(w(:)); end end img2 = uint8(img2); imshow(img2) imwrite(img2,'median_filter_2015.png','png');

Page 21: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Örnek: Gürültü Giderimi İçin Medyan Filtre Kullanımı

21

Matlab Kodu (medyan):

result = medfilt2(image);

Page 22: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri

22

►Amaç: yeğinlikteki geçişleri vurgulamaktır.

► Laplas İşleci

► Keskin Olmayan Maskeleme ve Yüksek Vurgulu Filtreleme

►Doğrusal Olmayan Görüntü Keskinleştirmede Birinci Derece Türevlerin Kullanılması — Gradyan

Page 23: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Altyapı

23

► Bir boyutlu bir f(x) fonksiyonunun birinci derece türevinin temel tanımı, aşağıdaki farktır:

► f(x)’in ikinci dereceden türevini, fark olarak şöyle tanımlarız:

( 1) ( )f

f x f xx

2

2( 1) ( 1) 2 ( )

ff x f x f x

x

Page 24: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

24

Page 25: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Laplas İşleci

25

► İki değişkenli bir fonksiyon (görüntü) f(x,y) için Laplas işleci şu şekilde tanımlanır:

2 22

2 2

f ff

x y

2

2( , 1) ( , 1) 2 ( , )

ff x y f x y f x y

y

2

2( 1, ) ( 1, ) 2 ( , )

ff x y f x y f x y

x

2 ( 1, ) ( 1, ) ( , 1) ( , 1)

- 4 ( , )

f f x y f x y f x y f x y

f x y

Page 26: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Laplas İşleci

26

Page 27: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Laplas İşleci

27

►Görüntü keskinleştirmek için Laplas işlecini şu şekilde kullanırız:

2

2

( , ) ( , ) ( , )

where,

( , ) is input image,

( , ) is sharpenend images,

-1 if ( , ) corresponding to Fig. 3.37(a) or (b)

and 1 if either of the other two filters is us

g x y f x y c f x y

f x y

g x y

c f x y

c

ed.

giriş görüntüsü

keskinleştirilmiş görüntü

c parametresi seçilen filtrenin durumuna göre -1

veya 1 olur.

burada

Page 28: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Laplas İşleci

28

Matlab Kodu:

kernel = -1 * ones(3); kernel(2,2) = 8; % Now kernel = [-1,-1,-1; -1,8,-1; -1,-1,-1] output = conv2(double(inputImage), kernel, 'same');

Önceden tanımlanmış 2 boyutlu filtre oluştur

input = imread('cameraman.tif'); h = fspecial('laplacian',alpha); alpha — Shape of the Laplacian 0.2 (default) output = imfilter(input,h, 'replicate'); imshow(output);

Page 29: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Uzamsal Keskinleştirme Filtreleri: Laplas İşleci

29

Önceden tanımlanmış 2 boyutlu filtre oluştur h = fspecial(type) h = fspecial('average',hsize) h = fspecial('disk',radius) h = fspecial('gaussian',hsize,sigma) h = fspecial('laplacian',alpha) h = fspecial('log',hsize,sigma) h = fspecial('motion',len,theta) h = fspecial('prewitt') h = fspecial('sobel')

Değer Açıklama

'average' Averaging filter

'disk' Circular averaging filter (pillbox)

'gaussian' Gaussian lowpass filter. Not recommended.

'laplacian' Approximates the two-dimensional Laplacian

'log' Laplacian of Gaussian filter

'motion' Approximates the linear motion of a camera

'prewitt' Prewitt horizontal edge-emphasizing filter

'sobel' Sobel horizontal edge-emphasizing filter

Page 30: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

30

Page 31: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Birinci Derece Türevlere Dayalı Görüntü Keskinleştirme

31

For function ( , ), the gradient of at coordinates ( , )

is defined as

grad( )x

y

f x y f x y

f

g xf f

fg

y

2 2

The of vector , denoted as ( , )

( , ) mag( ) x y

magnitude f M x y

M x y f g g

Gradyan görüntü

𝑓(𝑥, 𝑦) fonksiyonu için (𝑥, 𝑦) koordinatlarındaki 𝑓’in gradyanı

iki boyutlu sütun vektörü olarak tanımlanır:

𝛻𝑓 vektörünün, 𝑀(𝑥, 𝑦) olarak gösterilen büyüklüğü:

Page 32: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Birinci Derece Türevlere Dayalı Görüntü Keskinleştirme

32

2 2

The of vector , denoted as ( , )

( , ) mag( ) x y

magnitude f M x y

M x y f g g

( , ) | | | |x yM x y g g

z1 z2 z3

z4 z5 z6

z7 z8 z9

8 5 6 5( , ) | | | |M x y z z z z

𝛻𝑓 vektörünün, 𝑀(𝑥, 𝑦) olarak gösterilen büyüklüğü:

Page 33: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Birinci Derece Türevlere Dayalı Görüntü Keskinleştirme

33

Page 34: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Birinci Derece Türevlere Dayalı Görüntü Keskinleştirme

34

z1 z2 z3

z4 z5 z6

z7 z8 z9

9 5 8 6

Roberts Cross-gradient Operators

( , ) | | | |M x y z z z z

7 8 9 1 2 3

3 6 9 1 4 7

Sobel Operators

( , ) | ( 2 ) ( 2 ) |

| ( 2 ) ( 2 ) |

M x y z z z z z z

z z z z z z

Roberts çapraz gradyan operatörleri

Sobel operatörleri

Page 35: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Örnek

35

Page 36: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

36

Uzamsal Zenginleştirme Yöntemlerini Birleştirme Amaç: Görüntüyü keskinleştirerek ve iskelet ayrıntılarının çoğunu ortaya çıkararak zenginleştirmektir.

Örnek

Page 37: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

37

Örnek

Page 38: Bölüm 5 Uzamsal Filtreleme · 2018-10-25 · BLM429 Görüntü İşlemeye Giriş Dr. Öğr. Üyesi Caner ÖZCAN Bölüm 5 Uzamsal Filtreleme If the facts don't fit the theory, change

Kaynaklar

38

►Sayısal Görüntü İşleme, Palme Yayıncılık, Üçüncü

Baskıdan Çeviri (Orj: R.C. Gonzalez and R.E. Woods: "Digital Image Processing", Prentice Hall, 3rd edition, 2008).

►“Digital Image Processing Using Matlab”, Gonzalez & Richard E. Woods, Steven L. Eddins, Gatesmark Publishing, 2009

►Ders Notları, CS589-04 Digital Image Processing, F.(Qingzhong) Liu, http://www.cs.nmt.edu/~ip

►Ders Notları, BIL717-Image Processing, E.Erdem ►Ders Notları, EBM537-Görüntü İşleme, F.Karabiber