You are on page 1of 7

1

PRAKTIKUM
EL3008 PENGOLAHAN CITRA DIGITAL
MODUL 3 EDGE DETECTION


Penentuan tepian suatu objek dalam citra merupakan salah satu wilayah pengolahan citra digital yang
paling awal dan paling banyak diteliti. Proses ini seringkali ditempatkan sebagai langkah pertama
dalam aplikasi segmentasi citra, yang bertujuan untuk mengenali objek-objek yang terdapat dalam
citra ataupun konteks citra secara keseluruhan.
Deteksi tepi berfungsi untuk mengidentifikasi garis batas (boundary) dari suatu objek yang terdapat
pada citra. Tepian dapat dipandang sebagai lokasi piksel dimana terdapat nilai perbedaan intensitas
citra secara ekstrem. Sebuah edge detector bekerja dengan cara mengidentifikasi dan menonjolkan
lokasi-lokasi piksel yang memiliki karakteristik tersebut.

1. Operator Gradien
Pada citra digital f(x,y), turunan berarah sepanjang tepian objek akan bernilai maksimum pada arah
normal dari kontur tepian yang bersesuaian. Sifat ini dipergunakan sebagai dasar pemanfaatan
operator gradien sebagai edge detector.
Operator gradien citra konvensional melakukan diferensiasi intensitas piksel pada arah baris dan
kolom, mengikuti persamaan local intensity variation berikut :
) , ( ) , ( ) , ( y x f
y
y x f
x
f f y x f
y x
c
c
+
c
c
= + = V

Nilai magnitudo gradien |V(x,y)| dari persamaan di atas dapat dinyatakan sebagai berikut:
( ) ( )
2 2
) , (
y x
f f y x + = V
Operator gradien dapat direpresentasikan oleh dua buah kernel konvolusi G
x
dan G
y
, yang masing-
masing mendefinisikan operasi penghitungan gradien dalam arah sumbu x dan sumbu y yang saling
tegak lurus.
Dalam kasus penghitungan gradien dengan persamaan local intensity variation, maka kernel G
x
dan
G
y
dapat dirumuskan seperti berikut:
| |
(

=
=
1
1
1 1
y
x
G
G



2
Berikut adalah contoh fungsi Matlab untuk operasi penghitungan gradien orde satu:

















Dari operator gradien konvensional di atas, dapat diturunkan berbagai operator gradien berikut:

Operator Selisih Terpusat
Operator selisih terpusat juga dikenal sebagai Centered Difference Edge Detector Mask, dan
dinyatakan sebagai kernel:
| |
(
(
(

= =
1
0
1
1 0 1
y x
D D
















Operator Roberts
Operator Roberts memiliki ukuran kernel sebesar 22, yang direpresentasikan sebagai:
(

=
(

=
1 0
0 1

0 1
1 0
y x
R R


I = double(imread('cameraman.tif'));

% Konvolusi dengan operator selisih terpusat
d1x = [-1 0 1];
d1y = [-1;0;1];
Ix = conv2(I,d1x,'same');
Iy = conv2(I,d1y,'same');
J = sqrt((Ix.^2)+(Iy.^2));

% Gambar Hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));

% Gradien orde satu pada arah horizontal
gx = [-1 1];
Ix = conv2(I,gx,'same');

% Gradien orde satu pada arah vertikal
gy = [-1;1];
Iy = conv2(I,gy,'same');

% Magnitudo gradien
J = sqrt((Ix.^2)+(Iy.^2));

% Gambar hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
3
Contoh perintah menggunakan operator Roberts:














Contoh perintah menggunakan operator Roberts (matlab toolbox)
1
:






Operator Prewitt
(
(
(


=
(
(
(

=
1 1 1
0 0 0
1 1 1

1 0 1
1 0 1
1 0 1
y x
P P


Contoh perintah menggunakan operator Prewitt:














Contoh perintah menggunakan operator Prewitt (matlab toolbox):





1
Perintah edge (pada toolbox Matlab) untuk mensimulasikan operator Prewitt, Roberts, Sobel, dan lainnya memiliki konsep
dasar yang sama dengan operasi konvolusi kernel setiap operator secara manual. Bedanya, perintah edge menambahkan
suatu skema thresholding secara otomatis, sehingga dihasilkan citra keluaran yang bersifat biner (bernilai 0 atau 1).
I = double(imread('cameraman.tif'));

% Konvolusi dengan operator Roberts
robertshor = [0 1; -1 0];
robertsver = [1 0; 0 -1];
Ix = conv2(I,robertshor,'same');
Iy = conv2(I,robertsver,'same');
J = sqrt((Ix.^2)+(Iy.^2));

% Gambar Hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));
J = edge(I,'prewitt');
figure,imagesc(I),axis image,colormap gray,colorbar;
figure,imagesc(J),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));
J = edge(I,'roberts');
figure,imagesc(I),axis image,colormap gray,colorbar;
figure,imagesc(J),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));

%Konvolusi dengan operator Prewitt
prewitthor = [-1 0 1; -1 0 1; -1 0 1];
prewittver = [-1 -1 -1; 0 0 0; 1 1 1];
Ix = conv2(I,prewitthor,'same');
Iy = conv2(I,prewittver,'same');
J = sqrt((Ix.^2)+(Iy.^2));

%Gambar Hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
4
Operator Sobel
(
(
(


=
(
(
(

=
1 2 1
0 0 0
1 2 1

1 0 1
2 0 2
1 0 1
y x
S S


Contoh perintah menggunakan operator Sobel:














Contoh perintah menggunakan operator Sobel (matlab toolbox):






Operator Isotropic
(
(
(


=
(
(
(

=
1 2 1
0 0 0
1 2 1

1 0 1
2 0 2
1 0 1
y x
I I

Contoh perintah menggunakan operator isotropic:














I = double(imread('cameraman.tif'));
J = edge(I,'sobel');
figure,imagesc(I),axis image,colormap gray,colorbar;
figure,imagesc(J),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));

%Konvolusi dengan operator Sobel
sobelhor = [-1 0 1; -2 0 2; -1 0 1];
sobelver = [-1 -2 -1; 0 0 0; 1 2 1];
Ix = conv2(I,sobelhor,'same');
Iy = conv2(I,sobelver,'same');
J = sqrt((Ix.^2)+(Iy.^2));

%Gambar Hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
I = double(imread('cameraman.tif'));

%Konvolusi dengan operator isotropic
isohor = [-1 0 1; -sqrt(2) 0 sqrt(2); -1 0 1];
isover = [-1 -sqrt(2) -1; 0 0 0; 1 sqrt(2) 1];
Ix = conv2(I,isohor,'same');
Iy = conv2(I,isover,'same');
J = sqrt((Ix.^2)+(Iy.^2));

%Gambar Hasil
figure,imagesc(I ),axis image,colormap gray,colorbar;
figure,imagesc(Ix),axis image,colormap gray,colorbar;
figure,imagesc(Iy),axis image,colormap gray,colorbar;
figure,imagesc(J ),axis image,colormap gray,colorbar;
5
Operator Compass
Operator Compass bekerja menggunakan pola empat arah mata angin:
Utara


1 1 1
1 2 1
1 1 1
(
(
(


=
N
C

Selatan


1 1 1
1 2 1
1 1 1
(
(
(


=
S
C

Timur


1 1 1
1 2 1
1 1 1
(
(
(

=
E
C

Barat


1 1 1
1 2 1
1 1 1
(
(
(



=
W
C



Operator Kirsch
Operator Kirsch bekerja menggunakan pola delapan arah mata angin:
(
(
(

=
3 3 3
3 0 5
3 5 5
4
K

(
(
(


=
3 3 3
3 0 3
5 5 5
3
K

(
(
(

=
3 3 3
5 0 3
5 5 3
2
K


(
(
(




=
3 3 5
3 0 5
3 3 5
5
K

(
(
(


=
5 3 3
5 0 3
5 3 3
1
K


(
(
(


=
3 5 5
3 0 5
3 3 3
6
K

(
(
(



=
5 5 5
3 0 3
3 3 3
7
K

(
(
(


=
5 5 3
5 0 3
3 3 3
8
K


6
2. Operator Laplacian
Dalam kondisi transisi tepian yang lebih tidak ekstrem, penggunaan operator turunan kedua lebih
dianjurkan.
) , ( ) , ( ) , (
) , ( ) , (
) , (
2
2
2
2
2
2
y x f
y
y x f
x
y x f
y x f
y
y x f
x
f f y x f
y x
yy xx
c
c
+
c
c
= V
c
c
+
c
c
=
+ = V

Representasi turunan kedua dalam bentuk kernel operator Laplacian adalah sebagai berikut:
(
(
(



=
0 1 0
1 4 1
0 1 0
L

Dengan berbagai macam pembobotan, kernel Laplacian tersebut dapat dimodifikasi menjadi beberapa
kernel konvolusi berikut :
(
(
(




=
1 1 1
1 8 1
1 1 1
1
L

(
(
(



=
1 2 1
2 4 2
1 2 1
2
L


Laplacian of Gaussian
Turunan kedua memiliki sifat lebih sensitif terhadap noise, selain itu juga menghasilkan double edge.
Oleh karena itu, operator Laplacian dalam deteksi tepi pada umumnya tidak dipergunakan secara
langsung, namun dikombinasikan dengan suatu kernel Gaussian menjadi sebuah operator Laplacian
of Gaussian.
Fungsi transfer dari kernel Laplacian of Gaussian dapat dirumuskan sebagai berikut:
( )
( ) ( )
2 2 2
2 2 2
2 / ) (
2
2 2
4
2
2 / ) (
2
2
1
1
,
2
1
,
o
o
o to
to
y x
y x
e
y x
y x G
e y x G
+

+
= V
=


dimana o merupakan standar deviasi dari kernel Gaussian.
Contoh perintah untuk mendeteksi tepian dengan menggunakan operator Laplacian of Gaussian
(Matlab toolbox) adalah:




I = double(imread('cameraman.tif'));
J = edge(I,'log');
figure,imagesc(I),axis image,colormap gray,colorbar;
figure,imagesc(J),axis image,colormap gray,colorbar;
7
3. Operator Canny
Salah satu algoritma deteksi tepi modern adalah deteksi tepi dengan menggunakan metoda Canny.
Berikut adalah diagram blok algoritma Canny :




Contoh perintah untuk mendeteksi tepian menggunakan metoda Canny (matlab toolbox) :







4. Tugas
A. Pada percobaan dengan kernel Sobel, kernel Isotropic, dan kernel Compass, jelaskan mengenai
garis abu-abu yang ditemukan pada pinggiran citra hasil konvolusi.
B. Untuk citra cameraman.tif, edge detector manakah yang memberikan hasil terbaik? Berikan
analisis mengenai pendapat anda tersebut.
C. Sensitivitas edge detector terhadap noise dapat diukur dengan menggunakan parameter error
rate sebagai berikut:
R
R N
n
n n
P

=
dimana:
n
R
: jumlah piksel yang dinyatakan sebagai edge pada citra referensi
n
N
: jumlah piksel yang dinyatakan sebagai edge pada citra noisy
Nilai P yang besar menyatakan sensitivitas edge detector yang tinggi terhadap noise. Dalam
kasus citra cameraman.tif terkontaminasi oleh noise salt & pepper dengan distribusi 0.02,
edge detector manakah yang paling terpengaruh performansinya? Simulasikan dengan Matlab.



I = double(imread('cameraman.tif'));
J = edge(I,'canny');
figure,imagesc(I),axis image,colormap gray,colorbar;
figure,imagesc(J),axis image,colormap gray,colorbar;
Image
Smoothing
Differentiation
Nonmaximum
Suppression
Edge
Thresholding
original
image
edge
image
%Contoh perhitungan error rate untuk edge detector Sobel
%(kerjakan pula untuk jenis edge detector lain pada Matlab toolbox)

Ia = imread('cameraman.tif');
Ja = edge(Ia,'sobel');
In = imnoise(Ia,'salt & pepper',0.02);
Jn = edge(In,'sobel');
nr = sum(sum(Ja));
nn = sum(sum(Jn));
P = abs(nn-nr)/nr

You might also like