You are on page 1of 3

SEGMENTASI CITRA

Muhamad Taufik Yusuf


Email: klepitom@yahoo.com

TAMPILAN HASIL PROGRAM

LISTING PROGRAM

File Tugas_3.m

function varargout = Tugas_3(varargin)


% TUGAS_3 M-file for Tugas_3.fig
% TUGAS_3, by itself, creates a new TUGAS_3 or raises the existing
% singleton*.
%
% H = TUGAS_3 returns the handle to a new TUGAS_3 or the handle to
% the existing singleton*.
%
% TUGAS_3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TUGAS_3.M with the given input arguments.
%
% TUGAS_3('Property','Value',...) creates a new TUGAS_3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Tugas_3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Tugas_3_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 Tugas_3

% Last Modified by GUIDE v2.5 30-Jul-2009 11:29:22

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Tugas_3_OpeningFcn, ...
'gui_OutputFcn', @Tugas_3_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 Tugas_3 is made visible.


function Tugas_3_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 Tugas_3 (see VARARGIN)

% Choose default command line output for Tugas_3


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Tugas_3_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 cmdLoadCitra.
function cmdLoadCitra_Callback(hObject, eventdata, handles)
% hObject handle to cmdLoadCitra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[fileCitra, pathCitra] = uigetfile({'*.bmp; *.jpg; *.png; *.tif', 'File Citra
(*.bmp,*.jpg, *.png, *.tif)';
'*.bmp', 'File bitmap (*.bmp)';
'*.jpg', 'File jpeg(*.jpg)';
'*.png', 'File png (*.png)';
'*.tiff', 'File tif (*.tif)';
'*.*', 'Semua File (*.*)'}, 'buka file Citra');
if ~isequal(fileCitra, 0)
handles.dataCitra = imread(fullfile(pathCitra, fileCitra));
guidata(hObject,handles);
axes(handles.imgCitra);
imshow(handles.dataCitra);
else
return;
end

% --- Executes on button press in cmdSegmentasiCitra.


function cmdSegmentasiCitra_Callback(hObject, eventdata, handles)
% hObject handle to cmdSegmentasiCitra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

I = handles.dataCitra;

[junk threshold] = edge(I, 'sobel');


fudgeFactor = .5;
BWs = edge(I,'sobel', threshold * fudgeFactor);

se90 = strel('line', 3, 90);


se0 = strel('line', 3, 0);

BWsdil = imdilate(BWs, [se90 se0]);


BWdfill = imfill(BWsdil, 'holes');

BWnobord = imclearborder(BWdfill, 4);


seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);

BWoutline = bwperim(BWfinal);
Segout = I;
Segout(BWoutline) = 255;

handles.dataCitraSegmentasi = Segout;
guidata(hObject,handles);
axes(handles.imgCitraSegmentasi);
imshow(handles.dataCitraSegmentasi);

You might also like