-
Notifications
You must be signed in to change notification settings - Fork 0
/
Untitled2.m
49 lines (44 loc) · 1.18 KB
/
Untitled2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
img = imread ('c:/Gambar/bunga.jpg' ) ;
Grayscale = rgb2gray (img) ;
img2 = not (im2bw (Grayscale) ) ;
SE = [1 0 1;0 1 0;1 0 1] ;
% Operasi erosi
A = img2 ;
B = SE;
hotx = 1;
hoty = 1;
[ta, la]=size (A) ;
[tb, lb]=size (B) ;
Xb = [] ;
Yb = [] ;
jum_anggota = 0;
%Menentukan koordinat piksel bernilai 1 pada H
for baris = 1 : tb
for kolom = 1 : lb
if B(baris, kolom) == 1
jum_anggota = jum_anggota + 1;
Xb (jum_anggota) = -hotx + kolom;
Yb (jum_anggota) = -hoty + baris;
end
end
end
AB = ones (ta, la) ; % Beri nilai satu semua pada hasil erosi
%Memproses erosi
for baris = 1 : ta
for kolom = 1 : la
for indeks = 1 : jum_anggota
if A(baris, kolom) == 1
xpos = kolom + Xb (indeks) ;
ypos = baris + Yb (indeks) ;
if (xpos >= 1) && (xpos <= la) && ...
(ypos >= 1) && (ypos <= ta)
AB (ypos, xpos) = 0;
end
end
end
end
end
figure,
subplot (1,3, 1) , imshow (img) , title (' Citra Asli' ) ;
subplot (1,3,2) , imshow (img2), title ('Citra Biner' ) ;
subplot (1,3,3), imshow (AB) , title ( 'Operasi Erosi') ;