9 Morfologi Citra
1. Tujuan :
- Mahasiswa memahami konsep operasi morfologi seperti
operasi dilasi, erosi, opening dan closing.
- Mahasiswa mengenal perintah matlab yaitu
erote,imdilate,
2. Teori :
Operasi morfologi merupakan operasi yang umum
dikenakan pada citra biner (hitam-putih) untuk mengubah
struktur bentuk objek yang terkandung dalam citra.
Perhatikan contoh berikut:
3. Praktikum
Dilasi
Skrip operasi dilasi sebagai berikut:
function G = dilasi(F, H, hotx, hoty)
% DILASI Berguna untuk melaksanakan operasi dilasi.
% Masukan:
% F = citra yang akan dikenai dilasi
% H = elemen pentruksur
% (hy, hx) koordinat pusat piksel
[th, lh]=size(H);
[tf, lf]=size(F);
if nargin < 3
hotx = round(lh/2);
hoty = round(th/2);
end
Xh = [];
Yh = [];
jum_anggota = 0;
% Memproses dilasi
for baris = 1 : tf
for kolom = 1 : lf
for indeks = 1 : jum_anggota
if F(baris, kolom) == 1
xpos = kolom + Xh(indeks);
ypos = baris + Yh(indeks);
if (xpos >= 1) && (xpos <= lf) && ...
(ypos >= 1) && (ypos <= tf)
G(ypos, xpos) = 1;
end
end
end
end
end
Citra baru B :
0 0 0 0 0 0 0
0 0 1 1 1 1 0
0 1 1 1 1 1 1
0 1 1 1 1 1 1
0 0 1 1 1 1 1
0 1 1 1 1 1 0
1 1 1 1 0 0 0
0 1 1 0 0 0 0
img = imread('bunga.tif');
im = rgb2gray(img);
i = histeq(im);
subplot(2,3,1);imshow(img);
subplot(2,3,2);imshow(im);
subplot(2,3,3);imshow(i);
subplot(2,3,5);imhist(im);
subplot(2,3,6);imhist(i)
strel
Perintah SE = strel(shape, parameters) membuat structuring
element dengan bentuk sesuatu dengan parameter shape
dan parameter lainya.
imdilate
fungsi imdilate digunakan umtuk melakukan dilasi dengan
structuring element yang dibuat menggunakan fungsi strell.
Bravo = imread('bravo.png');
BW = im2bw(Bravo, 0.5);
H = ones(4);
subplot(3,1,1);imshow(Bravo);
subplot(3,1,2);imshow(BW);
subplot(3,1,3);imshow(dilasi(BW, H));
Bravo = imread('bravo.png');
BW = im2bw(Bravo, 0.5);
SE = strel('disk',8);
H = imdilate(BW, SE);
subplot(3,1,1);imshow(Bravo);
subplot(3,1,2);imshow(BW);
subplot(3,1,3);imshow(H);