Tugas Keenam Pengolahan Citra Digital

A.    OPERATOR LAPLACIAN

1.      Titik-titik tepi lacak dengan cara menemukan titik perpotongan dengan sumbu x oleh turunan kedua → sehigga sering disebut sebagai zero crossing operator b.

2.      Sangat sensitihf terhadap noise yang terletak pada titik-titik tepi → dapat diatasi dengan Laplacian of Gaussian yang merupakan kombinasi dari operator Laplacian dengan operator Gaussian.

 

    B. OPERATOR LAPLACIAN OF GAUSSIAN (LOG)

Dapat dilakukan dengan cara :

1.      Sebuah citra di konvolusi dengan operator gaussian, kemudian hasilnya di konvolusi dengan operator laplacian.

2.      Di konvolusi langsung dengan menggunakan operator Laplacian of Gaussian.

 

Source code pendeteksian tepi dengan operator laplace ditunjukkan oleh barisan perintah berikut:

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 diatas disimpan dengan nama m-file ‘laplacian.m’ . Selanjutnya untuk menguji keberhasilan source code di atas, buatlah suatu m-file lagi dan tuliskan source code berikut:

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)

 

Output yang dihasilkan oleh source code di atas berturut-turut hasil konvolusi matriks dengan mask dan hasil akhir setelah dilakukan thresholding adalah sebagai berikut :

 

 


 

Kemudian, source code melakukan edge detection pada citra ‘cameraman.tif’ adalah berikut:

clear; clc;

I = imread(‘cameraman.tif’);

Hsl = laplacian(im2double(I), 0.25);

imshow(I);

figure, imshow(im2uint8(Hsl));

 

hasil tampilannya :

 


 

deteksi sisi yang dilakukan oleh operator laplacian menghasilkan tepi yang lebih akurat dibandingkan dengan operator gradien meskipun dengan nilai threshold luminance yang sama.

 

 

Deteksi Tepi Menggunakan Operator Prewitt, Sobel, Roberts, Canny, dan LOG

 

Source Code :

 

function varargout = openbtn1(varargin)

 

% OPENBTN1 M-file for openbtn1.fig

 

%      OPENBTN1, by itself, creates a new OPENBTN1 or raises the existing

 

%      singleton*.

 

%

 

%      H = OPENBTN1 returns the handle to a new OPENBTN1 or the handle to

 

%      the existing singleton*.

 

%

 

%      OPENBTN1(‘CALLBACK’,hObject,eventData,handles,…) calls the local

 

%      function named CALLBACK in OPENBTN1.M with the given input arguments.

 

%

 

%      OPENBTN1(‘Property’,’Value’,…) creates a new OPENBTN1 or raises the

 

%      existing singleton*.  Starting from the left, property value pairs are

 

%      applied to the GUI before openbtn1_OpeningFcn gets called.  An

 

%      unrecognized property name or invalid value makes property application

 

%      stop.  All inputs are passed to openbtn1_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 openbtn1

 

% Last Modified by GUIDE v2.5 18-Apr-2019 20:48:43

 

% Begin initialization code – DO NOT EDIT

 

gui_Singleton = 1;

 

gui_State = struct(‘gui_Name’,       mfilename, …

 

                   ‘gui_Singleton’,  gui_Singleton, …

 

                   ‘gui_OpeningFcn’, @openbtn1_OpeningFcn, …

 

                   ‘gui_OutputFcn’,  @openbtn1_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 openbtn1 is made visible.

 

function openbtn1_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 openbtn1 (see VARARGIN)

 

% Choose default command line output for openbtn1

 

handles.output = hObject;

 

% Update handles structure

 

guidata(hObject, handles);

 

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

 

% uiwait(handles.figure1);

 

% — Outputs from this function are returned to the command line.

 

function varargout = openbtn1_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 Open.

 

% Code tombol Open —-

 

function Open_Callback(hObject, eventdata, handles)

 

open=guidata(gcbo);

 

[namafile,direktori]=uigetfile({‘*.jpg;*.bmp;*.tif’},’OpenImage’);

 

I=imread(namafile);

 

set(open.figure1,’CurrentAxes’,open.axes1);

 

set(imagesc(I));colormap(‘gray’);

 

set(open.axes1,’Userdata’,I);

 

% hObject    handle to Open (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 pushbutton2.

 

% Code Tombol operator Prewitt

 

function pushbutton2_Callback(hObject, eventdata, handles)

 

proyek=guidata(gcbo);

 

I=get(proyek.axes1,’Userdata’);

 

gray=rgb2gray(I);

 

BW=edge(gray,’prewitt’);

 

set(proyek.figure1,’CurrentAxes’,proyek.axes2);

 

set(imshow(BW));

 

set(proyek.axes2,’Userdata’,I);

 

redo_Callback(hObject,eventdata, handles);

 

% hObject    handle to pushbutton2 (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 pushbutton3.

 

% Code Tombol operator Robert

 

function pushbutton3_Callback(hObject, eventdata, handles)

 

proyek=guidata(gcbo);

 

I=get(proyek.axes1,’Userdata’);

 

gray=rgb2gray(I);

 

BW=edge(gray,’roberts’);

 

set(proyek.figure1,’CurrentAxes’,proyek.axes2);

 

set(imshow(BW));

 

set(proyek.axes2,’Userdata’,A);

 

redo_Callback(hObject,eventdata, handles);

 

% hObject    handle to pushbutton3 (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 pushbutton4.

 

% Code Tombol operator Canny

 

function pushbutton4_Callback(hObject, eventdata, handles)

 

proyek=guidata(gcbo);

 

I=get(proyek.axes1,’Userdata’);

 

gray=rgb2gray(I);

 

BW=edge(gray,’canny’);

 

set(proyek.figure1,’CurrentAxes’,proyek.axes2);

 

set(imshow(BW));

 

set(proyek.axes2,’Userdata’,A);

 

redo_Callback(hObject,eventdata, handles);

 

% hObject    handle to pushbutton4 (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 pushbutton5.

 

% Code Tombol operator Sobel

 

function pushbutton5_Callback(hObject, eventdata, handles)

 

proyek=guidata(gcbo);

 

I=get(proyek.axes1,’Userdata’);

 

gray=rgb2gray(I);

 

BW=edge(gray,’sobel’);

 

set(proyek.figure1,’CurrentAxes’,proyek.axes2);

 

set(imshow(BW));

 

set(proyek.axes2,’Userdata’,A);

 

redo_Callback(hObject,eventdata, handles);

 

% hObject    handle to pushbutton5 (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 pushbutton6.

 

% Code Tombol operator LOG

 

function pushbutton6_Callback(hObject, eventdata, handles)

 

proyek=guidata(gcbo);

 

I=get(proyek.axes1,’Userdata’);

 

gray=rgb2gray(I);

 

BW=edge(gray,’log’);

 

set(proyek.figure1,’CurrentAxes’,proyek.axes2);

 

set(imshow(BW));

 

set(proyek.axes2,’Userdata’,A);

 

redo_Callback(hObject,eventdata, handles);

 

% hObject    handle to pushbutton6 (see GCBO)

 

% eventdata  reserved – to be defined in a future version of MATLAB

 

% handles    structure with handles and user data (see GUIDATA)

 

% — Executes during object creation, after setting all properties.

 

function pushbutton2_CreateFcn(hObject, eventdata, handles)

 

% hObject    handle to pushbutton2 (see GCBO)

 

% eventdata  reserved – to be defined in a future version of MATLAB

 

% handles    empty – handles not created until after all CreateFcns called

 

 

Hasil Tampilan Dari Tiap Masing Pengolahan :

     1.      Operator Prewit


     2.      Operator Robert


     3.      Operator Canny


     4.      Operator Sobel


     5.      Operator LOG

Tidak ada komentar

Diberdayakan oleh Blogger.