Anda di halaman 1dari 27

Tugas

ANALISIS OPERATOR DETEKSI TEPI

MATAKULIAH : PENGOLAHAN CITRA DIGITAL


DOSEN : ASSOC. PROF. DR. SETYAWAN WIDYARTO

Oleh:
SUHENDI
1311600959

PROGRAM STUDI: MAGISTER ILMU KOMPUTER (MKOM)

PROGRAM PASCASARJANA

UNIVERSITAS BUDI LUHUR

JAKARTA

2015
BAB. I PENDAHULUAN

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 :

Nilai magnitudo gradien |∇(x,y)| dari persamaan di atas dapat dinyatakan sebagai
berikut:

Operator gradien dapat direpresentasikan oleh dua buah kernel konvolusi Gx dan Gy, 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 Gx dan Gy dapat dirumuskan seperti berikut:
Berikut adalah contoh fungsi Matlab untuk operasi penghitungan gradien orde satu:

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 ),colormap('gray'),colorbar('vert');

figure,imagesc(Ix),colormap('gray'),colorbar('vert');

figure,imagesc(Iy),colormap('gray'),colorbar('vert');

figure,imagesc(J ),colormap('gray'),colorbar('vert');

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

1.1 Operator Selisih Terpusat


Operator selisih terpusat juga dikenal sebagai Centered Difference Edge Detector
Mask, dan dinyatakan sebagai kernel:
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 ),colormap('gray'),colorbar('vert');

figure,imagesc(Ix),colormap('gray'),colorbar('vert');

figure,imagesc(Iy),colormap('gray'),colorbar('vert');

figure,imagesc(J ),colormap('gray'),colorbar('vert');

1.2 Operator Roberts


Operator Roberts memiliki ukuran kernel sebesar 2×2, yang direpresentasikan
sebagai:

Contoh perintah menggunakan operator Roberts:

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 ),colormap('gray'),colorbar('vert');

figure,imagesc(Ix),colormap('gray'),colorbar('vert');

figure,imagesc(Iy),colormap('gray'),colorbar('vert');

figure,imagesc(J ),colormap('gray'),colorbar('vert');

Contoh perintah menggunakan operator Roberts (matlab toolbox) 1:

I = imread('cameraman.tif');

J = edge(I,'roberts');

figure,imagesc(I),colormap('gray'),colorbar('vert');

figure,imagesc(J),colormap('gray'),colorbar('vert');

1.3 Operator Prewitt

Contoh perintah menggunakan operator Prewitt:

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 ),colormap('gray'),colorbar('vert');

figure,imagesc(Ix),colormap('gray'),colorbar('vert');

figure,imagesc(Iy),colormap('gray'),colorbar('vert');

figure,imagesc(J ),colormap('gray'),colorbar('vert');

Contoh perintah menggunakan operator Prewitt (matlab toolbox):

I = imread('cameraman.tif');

J = edge(I,'prewitt');

figure,imagesc(I),colormap('gray'),colorbar('vert');

figure,imagesc(J),colormap('gray'),colorbar('vert');

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).

1.4 Operator Sobel


Contoh perintah menggunakan operator Sobel:

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 ),colormap('gray'),colorbar('vert');

figure,imagesc(Ix),colormap('gray'),colorbar('vert');

figure,imagesc(Iy),colormap('gray'),colorbar('vert');

figure,imagesc(J ),colormap('gray'),colorbar('vert');

Contoh perintah menggunakan operator Sobel (matlab toolbox):

I = imread('cameraman.tif');

J = edge(I,'sobel');

figure,imagesc(I),colormap('gray'),colorbar('vert');

BAB II. PEMBAHASAN ANALISA OPERATOR


Pada Jurnal “Sobel Edge Detection Algorithm”

A. original
G 1 = 2G = [(c - g - a + i) + 2(/ - d), (c - g + a - i) + 2(b - h)]

+1 +2 +1 -1 0 +1
-2 0 +2 -2 0 +2

-1 0 +1 -1 0 +1

kernelnya 3×3 untuk 5×5 sebagai gradien

G 1 = [20(n - l) + l0(i - r - g + t + o - k)]


+S(e - v - a + z) + 4(d - w - b + y)
+8(j - p - f + u), 20(h - s) + l0(i - r + g - t)
+ S(e - v + a - z) + 4(j - p + f - u)
+(d - w + b - y)]

Vertical

-5 -4 0 4 5

-8 -10 0 10 8

-10 -20 0 20 10

-8 -10 0 10 8

-5 -4 0 4 5

Horizontal
5 8 10 8 5

4 10 20 10 4

0 0 0 0 0

-4 -10 -20 -10 -4

-5 -8 -10 -8 -5

Untuk memperjelas dalam melakukan pergantian operator diatas maka akan dibuat
simulasi dibawah ini.
B. operator change

a. Pra Pengetahuan sebelum masuk ke deteksi tepi

patokan tabel arah :


untuk pencarian titik pusat citra :
Table 3.1 Arah 8 Titik
No. Arah Sumbu X Sumbu Y
1 0° x=x+1 y
2 135° x=x-1 y=y-1
3 225° x=x-1 y=y+1
4 315° x=x-1 y=y-1
5 45° x=x+1 y=y-1
6 270° x y=y+1
7 180° x=x-1 y
8 90° x y=y–1

perintah untuk melakukan konvolusi terhadap matriks I yang berukuran 5×5 dan
kernel yang berukuran 3×3 adalah sebagai berikut :
function B = convolve(A, k); [r c] = size(A);
[m n] = size(k);
h = rot90(k, 2);
center = floor((size(h)+1)/2);
left = center(2) -
1; right = n -
center(2); top =
center(1) - 1;
bottom = m -
center(1);
Rep = zeros(r + top + bottom, c + left + right);
for x = 1 + top : r
+ top for y = 1
+ left : c + left
Rep(x,y) = A(x - top, y - left);
end
end
B=
zeros(r ,
c); for x =
1:r
for y = 1
: c for i
=1:m
for j = 1 : n
q = x - 1;
w = y -1;
B(x, y) = B(x, y) + (Rep(i + q, j + w) * h(i, j));
end
end
end
end

Source code di atas disimpan dengan nama m-file ‘convolve.m’.

Selanjutnya untuk menguji keberhasilan source code di atas, buatlah suatu m-file
lagi dan tuliskan source code di bawah ini :

clear; clc;
clear; clc;

I = [4 4 3 5 4;
6 6 5 5 2;
5 6 6 6 2;
6 7 5 5 3;
3 5 2 4 4];

k = [0 -1 0;
-1 4 -1;
0 -1 0];
Hsl = convolve(I, k)

Operasi konvolusi yang dilakukan adalah dengan melibatkan zero padding di


dalamnya. Output yang dihasilkan oleh source code di atas adalah sebagai berikut :

Hsl =

6 3 -2 8 9
9 3 0 2 -3
2 0 2 6 -3
9 6 0 2 1
1 8 -6 5 9

perintah untuk melakukan konvolusi pada citra 'hendi.png' adalah


sebagai berikut :
clear; clc;
I = imread('hendi.png');
k = ones(3)/9;
Hsl = convolve(I, k); imshow(I);
figure, imshow(uint8(Hsl));
Gambar Original

Hasil konvulsi
perintah untuk melakukan neighborhood averaging dengan kernel berukuran
3×3:
clear; clc;

A = imread('hendi.png);
A = imnoise(A, 'salt & pepper', 0.01);
k = ones(3)/ 9;
[r c] = size(A);
[m n] = size(k);
h = rot90(k, 2);
center = floor((size(h)
+1)/2); left =
center(2) - 1;
right = n - center(2);
top = center(1) -
1; bottom = m -
center(1);
Rep = zeros(r + top + bottom, c + left + right);

for x = 1 + top : r + top


for y = 1 + left : c + left
Rep(x,y) = A(x - top, y - left);
end
end
B = zeros(r , c);
for x = 1 : r
for y = 1 : c
for i = 1 : m
for j = 1 : n
q = x - 1;
w = y -1;
B(x, y) = B(x, y) + (Rep(i + q, j + w) * h(i, j));
end
end
end
end
figure, imshow(A);
figure, imshow(uint8(B));

Median Filtering

perintah untuk melakukan median filtering terhadap citra yang


terkena
gangguan dengan kernel berukuran 3×3 :
clear; clc;
%READ AN 2D IMAGE
A=imread('hendi.png');
title('IMAGE WITH SALT AND PEPPER NOISE');
figure,imshow(A);

%PAD THE MATRIX WITH ZEROS ON ALL SIDES


modifyA=zeros(size(A)+2);
B=zeros(size(A));

%COPY THE ORIGINAL IMAGE MATRIX TO THE PADDED MATRIX


for x=1:size(A,1)
for y=1:size(A,2)
modifyA(x+1,y+1)=A(x,y);
end
end
%LET THE WINDOW BE AN ARRAY
%STORE THE 3-by-3 NEIGHBOUR VALUES IN THE ARRAY
%SORT AND FIND THE MIDDLE ELEMENT

for i= 1:size(modifyA,1)-2
for j=1:size(modifyA,2)-2
window=zeros(9,1);
inc=1;
for x=1:3
for y=1:3
window(inc)=modifyA(i+x-1,j+y-1);
inc=inc+1;
end
end

med=sort(window);
%PLACE THE MEDIAN ELEMENT IN THE OUTPUT MATRIX
B(i,j)=med(5);

end
end
%CONVERT THE OUTPUT MATRIX TO 0-255 RANGE IMAGE TYPE
B=uint8(B);
title('IMAGE AFTER MEDIAN FILTERING');
figure,imshow(B);

b. Proses deteksi tepi

Untuk melihat perbedaan antar operator akan diperbandingkan


antara sobel, Laplacian of Gaussian dan canny

1. Operator Sobel

Metode Sobel merupakan pengembangan metode robert dengan


menggunakan filter HPF yang diberi satu angka nol penyangga.
Metode ini mengambil prinsip dari fungsi laplacian dan gaussian yang
dikenal sebagai fungsi untuk membangkitkan HPF. Kelebihan dari
metode sobel ini adalah kemampuan untuk mengurangi noise sebelum
melakukan perhitungan deteksi tepi.
Source code pendeteksian tepi dengan operator gradien pertama ditunjukkan
oleh barisan perintah di bawah ini.
function J = edge_detection(I, Thres)
Gx = [-1 1];
Gy = [-1 1];
Gradien_x = convolve(I,
Gx) Gradien_y =
convolve(I, Gy)
Magnitudo = sqrt((Gradien_x.^2) + (Gradien_y.^2))
%Arah_Gradien =
atan(Gradien_y./Gradien_x); J =
thresholding(Magnitudo, Thres);
function B = convolve(A, k)
[r c] = size(A);
[m n] = size(k);
h = rot90(k, 2);
center = floor((size(h)+1)/2);
left = center(2) - 1;
right = n - center(2);
top = center(1) - 1;
bottom = m -
center(1);
Rep = zeros(r + top + bottom, c + left + right);
for x = 1 + top : r +
top for y = 1 + left
: c + left
Rep(x,y) = A(x - top, y - left);
end
end
B = zeros(r ,
c); for x = 1 : r
for y = 1 : c
for i = 1 : m
for j = 1 :
n
q = x - 1;
w = y -1;
B(x, y) = B(x, y) + (Rep(i + q, j + w) * h(i, j));
end
end
end
end
function Hasil = thresholding(Array, T)
row = size(Array,
1); col = size(Array,
2); Hasil =
zeros(row, col); for
x = 1 : row
for y = 1 : col
if Array(x, y) >= T
Hasil(x, y) = 1;
else
Hasil(x, y) = 0;
end
end
end

Source code di atas disimpan dengan nama m-file ‘edge_detection.m’.


Contoh perintah untuk melakukan edge detection pada citra ‘hendi.png’ adalah
sebagai berikut :
%Fungsi dari edge detection
function J = edge_detection(I, Thres)
Gx = [-1 1];
Gy = [-1 1];
Gradien_x = convolve(I, Gx);
Gradien_y = convolve(I, Gy);
Magnitudo = sqrt((Gradien_x.^2) + (Gradien_y.^2));
%Arah_Gradien = atan(Gradien_y./Gradien_x);
J = thresholding(Magnitudo, Thres);

function B = convolve(A, k)
[r, c] = size(A);
[m, n] = size(k);
h = rot90(k, 2);
center = floor((size(h)+1)/2);
left = center(2) - 1;
right = n - center(2);
top = center(1) - 1; bottom = m - center(1);
Rep = zeros(r + top + bottom, c + left + right);
for x = 1 + top : r + top
for y = 1 + left : c + left
Rep(x,y) = A(x - top, y - left);
end
end

B = zeros(r , c);
for x = 1 : r
for y = 1 : c
for i = 1 : m
for j = 1 : n
q = x - 1;
w = y -1;
B(x, y) = B(x, y) + (Rep(i + q, j + w) * h(i, j));
end
end
end
end

function Hasil = thresholding(Array, T)


row = size(Array, 1);
col = size(Array, 2);
Hasil = zeros(row, col);
for x = 1 : row
for y = 1 : col

if Array(x, y) >= T

Hasil(x, y) = 1;
else
Hasil(x, y) = 0;
end
end
end

Program sobel
clear; clc;
I = imread('hendi.png');
Hsl = edge_detection(im2double(I), 0.04);
figure, imshow(im2uint8(Hsl));

Hasil pendeteksian sisi dengan nilai threshold 0.4


2. Operator Laplacian of Gaussian (LOG)
Dapat dilakukan dengan cara:
a. Sebuah citra di konvolusi dengan operator gaussian, kemudian hasilnya
di konvolusi dengan operator laplacian
b. Di konvolusi langsung dengan menggunakan operator Laplacian of
Gaussian

Source code pendeteksian tepi dengan operator laplace ditunjukkan oleh


barisan perintah dibawah ini.
function J = laplacian(I, Thres)
Mask = [0 1 0;
1 -4 1;
0 1 0];
Tepi = convolve(I, Mask);
J = thresholding(Tepi, Thres);

function B = convolve(A, k)
[r, c] = size(A);
[m, n] = size(k);
h = rot90(k, 2);
center = floor((size(h)+1)/2);
left = center(2) - 1;
right = n - center(2); top = center(1) - 1; bottom = m -
center(1);
Rep = zeros(r + top + bottom, c + left + right);
for x = 1 + top : r + top
for y = 1 + left : c + left
Rep(x,y) = A(x - top, y - left);
end
end

B = zeros(r , c);
for x = 1 : r
for y = 1 : c
for i = 1 : m
for j = 1 : n
q = x - 1;
w = y -1;
B(x, y) = B(x, y) + (Rep(i + q, j + w) * h(i, j));
end
end
end
end

function Hasil = thresholding(Array, T)


row = size(Array, 1);
col = size(Array, 2);
Hasil = zeros(row, col);
for x = 1 : row
for y = 1 : col
if Array(x, y) >= T
Hasil(x, y) = 1;
else
Hasil(x, y) = 0;
end
end
end

Source code di atas disimpan dengan nama m-file ‘laplacian.m’.

Selanjutnya untukmenguji keberhasilan source code di atas, buatlah


suatu m-file lagi dan tuliskan source code di bawah ini :
clear; clc;
I = [4 4 4 8 8 8 8;
4 4 4 8 8 8 8;
4 4 4 8 8 8 8;
4 4 4 8 8 8 8;
4 4 4 8 8 8 8];
Hsl = laplacian(I, 1.0)
Hsl =
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0

Contoh perintah untuk melakukan edge detection pada citra


'hendi.png’ adalah sebagai berikut :
clear; clc;

I = imread('hendi.png');
Hsl = laplacian(im2double(I), 0.04);
imshow(I);
figure, imshow(im2uint8(Hsl));

Hasil pendeteksian sisi dengan nilai threshold 0.04

Perhatikan bahwa pendeteksian sisi yang dilakukan oleh


operator laplacian menghasilkan tepi yang lebih detail dibandingkan dengan
operator gradien sobel meskipun dengan nilai threshold luminance yang sama.
Namun dari sisi tepi tetap sobel lebih kuat.

c. Aplikasi Deteksi Tepi


Untuk merperjelas dari hasil analisa operator deteksi tepi, dibawah ini
akan dibuat aplikasi GUI nya.

function varargout = sobel_suhendi(varargin)


% SOBEL_SUHENDI MATLAB code for sobel_suhendi.fig
% SOBEL_SUHENDI, by itself, creates a new SOBEL_SUHENDI or
raises the existing
% singleton*.
%
% H = SOBEL_SUHENDI returns the handle to a new SOBEL_SUHENDI
or the handle to
% the existing singleton*.
%
% SOBEL_SUHENDI('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in SOBEL_SUHENDI.M with the given
input arguments.
%
% SOBEL_SUHENDI('Property','Value',...) creates a new
SOBEL_SUHENDI or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before sobel_suhendi_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to sobel_suhendi_OpeningFcn
via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows
only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help sobel_suhendi

% Last Modified by GUIDE v2.5 22-Jun-2015 18:01:52

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @sobel_suhendi_OpeningFcn,
...
'gui_OutputFcn', @sobel_suhendi_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before sobel_suhendi is made visible.


function sobel_suhendi_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to sobel_suhendi (see
VARARGIN)

% Choose default command line output for sobel_suhendi


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes sobel_suhendi wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = sobel_suhendi_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in buka.


function buka_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
[nama,direktori]=uigetfile({'*.jpg';'*.bmp';'*.png';'*.tif'},'Buka
Gambar');
if isequal(nama,0)
return;
end;
eval(['cd ''' direktori ''';']);
i=imread(nama);
set(proyek.figure1,'CurrentAxes',proyek.axes1);
set(imshow(i));
set(proyek.figure1,'Userdata',i);
set(proyek.axes1,'Userdata',i);
% hObject handle to buka (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in sobel.


function prewitt_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
I=get(proyek.axes1,'Userdata');
if isequal(I,[])
warndlg('Belum ada gambar !','Prewitt Process error');
else
gray=rgb2gray(I);
BW=edge_detection(gray,'prewitt');
px=[-1 0 1;-1 0 1;-1 0 1];
grayx=filter2(px,gray);
py=px';
grayy=filter2(py,gray);
edge_p=sqrt(grayx.^2+grayy.^2);
BW=im2bw(edge_p/255,0.7);
set(proyek.figure1,'CurrentAxes',proyek.axes2);
set(imshow(BW));
set(proyek.axes2,'Userdata',BW);
end
%end;
% hObject handle to sobel (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in roberts.


function roberts_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
I=get(proyek.axes1,'Userdata');
if isequal(I,[])
warndlg('Belum ada gambar !','roberts Process error');
else
gray=rgb2gray(I);
BW=edge_detection(gray,'roberts');
px=[0 1;-1 0];
grayx=filter2(px,gray);
py=px';
grayy=filter2(py,gray);
edge_p=sqrt(grayx.^2+grayy.^2);
BW=im2bw(edge_p/255,0.7);
set(proyek.figure1,'CurrentAxes',proyek.axes3);
set(imshow(BW));
set(proyek.axes3,'Userdata',BW);
end
% hObject handle to roberts (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in sobel.


function sobel_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
I=get(proyek.axes1,'Userdata');
if isequal(I,[])
warndlg('Belum ada gambar1','Sobel process error');
else
gray=rgb2gray(I);
BW=edge_detection(gray,'sobel');
px=[-1 0 1;-2 0 1;-1 0 1];
grayx=filter2(px,gray);
py=px';
grayy=filter2(py,gray);
edge_p=sqrt(grayx.^2+grayy.^2);
BW=im2bw(edge_p/255,0.7);
set(proyek.figure1,'CurrentAxes',proyek.axes4);
set(imshow(BW));
set(proyek.axes4,'Userdata',BW);
end
% hObject handle to sobel (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in canny.


function canny_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
I=get(proyek.axes1,'Userdata');
gray=rgb2gray(I);
BW2 = edge_detection(gray,'canny_old');
set(proyek.figure1,'CurrentAxes',proyek.axes5);
set(imshow(BW2));
set(proyek.axes5,'Userdata',BW2);
% hObject handle to canny (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in log.


function log_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
I=get(proyek.axes1,'Userdata');
gray=rgb2gray(I);
BW = edge_detection(gray,'log');
BW = laplacian(im2bw(I), 0.7);
set(proyek.figure1,'CurrentAxes',proyek.axes6);
set(imshow(BW));
set(proyek.axes6,'Userdata',BW);
% hObject handle to log (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in Simpan.


function Simpan_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
[namafile,direktori]=uiputfile({'*.jpg';'*.*'},'Simpan Citra');
I=get(proyek.axes4,'Userdata');
imwrite(I,strcat(direktori,namafile));
% hObject handle to Simpan (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Keluar.
function Keluar_Callback(hObject, eventdata, handles)
selection=questdlg(['Keluar ' get(handles.figure1,'Name')''],...
['Keluar ' get(handles.figure1,'Name')''],...
'Ya','Tidak','Ya');
if strcmp(selection,'Tidak')
return;
end
delete(handles.figure1)
% hObject handle to Keluar (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

Hasil Sobel :

Hasil canny :

Hasil Laplacian of Gaussian (LOG) :


BAB II. PENUTUP

KESIMPULAN :
1. Dilihat dari hasil pembahasan diatas maka hasil operator LOG cukup
baik namun tetap masih lebih akurat atau detail adalah operator Sobel.
2. Dalam kasus ini, ternyata operator cain tidak cock untuk algpritma ini.
3. Pembahasan analisa operator ini bisa sebagai data untuk memperkuat
dari jurnal sebelumnya yaitu tentang “Sobel Edge Detection
Algorithm”

Referensi :

[1] Modul Praktikum Pengolahan Citra Digital 2014 – 2015, labpcmud_itn.com ©2015 Laboratorium
Multimedia & Pengolahan Citra

[2] Sobel Edge Detection Algorithm, Samta Gupta Susmita Ghosh Mazumdar, International Journal of
Computer Science and Management Research, Volume (3) Issue.

Anda mungkin juga menyukai