Implementasi Contra Harmonic Mean Filter Untuk Mereduksi Noise Pada Citra Digital

LAMPIRAN A-1

LISTING PROGRAM

1. Menu
function varargout = MENU(varargin)
% MENU M-file for MENU.fig
%
MENU, by itself, creates a new MENU or raises the existing
%
singleton*.
%
%
H = MENU returns the handle to a new MENU or the handle to
%
the existing singleton*.
%
%
MENU('CALLBACK',hObject,eventData,handles,...) calls the
local
%

function named CALLBACK in MENU.M with the given input
arguments.
%
%
MENU('Property','Value',...) creates a new MENU or raises
the
%
existing singleton*. Starting from the left, property
value pairs are
%
applied to the GUI before MENU_OpeningFunction gets
called. An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to MENU_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 MENU
% Last Modified by GUIDE v2.5 13-Mar-2014 07:15:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MENU_OpeningFcn, ...
'gui_OutputFcn', @MENU_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 MENU is made visible.
function MENU_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.

Universitas Sumatera Utara

LAMPIRAN A-2

% hObject
% eventdata
MATLAB
% handles
% varargin


handle to figure
reserved - to be defined in a future version of
structure with handles and user data (see GUIDATA)
command line arguments to MENU (see VARARGIN)

% Choose default command line output for MENU
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MENU wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command
line.
function varargout = MENU_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;
axes(handles.axes1);
imshow('D:\TA-USU-2014\NITIKA\Program\Fractals.jpg');
% ------------------------------------------------------------------function mnuKomp_Callback(hObject, eventdata, handles)
% hObject
handle to mnuKomp (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
NoiseRemove
% ------------------------------------------------------------------function Untitled_1_Callback(hObject, eventdata, handles)
% hObject
handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of

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

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

Universitas Sumatera Utara

LAMPIRAN A-3

function figure1_CreateFcn(hObject, eventdata, handles)

% hObject
handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
empty - handles not created until after all
CreateFcns called

% --- Executes during object creation, after setting all
properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject
handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% ------------------------------------------------------------------function Abt_Callback(hObject, eventdata, handles)
% hObject
handle to Abt (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB

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

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

2. Reduksi Noise

function varargout = NoiseRemove(varargin)
% NOISEREMOVE M-file for NoiseRemove.fig
%
NOISEREMOVE, by itself, creates a new NOISEREMOVE or raises
the existing

%
singleton*.
%
%
H = NOISEREMOVE returns the handle to a new NOISEREMOVE or
the handle to
%
the existing singleton*.
%
%
NOISEREMOVE('CALLBACK',hObject,eventData,handles,...) calls
the local
%
function named CALLBACK in NOISEREMOVE.M with the given input
arguments.
%
%
NOISEREMOVE('Property','Value',...) creates a new NOISEREMOVE
or raises the
%

existing singleton*. Starting from the left, property value
pairs are
%
applied to the GUI before NoiseRemove_OpeningFunction gets
called. An

Universitas Sumatera Utara

LAMPIRAN A-4

%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to NoiseRemove_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 NoiseRemove
% Last Modified by GUIDE v2.5 20-Mar-2014 09:53:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @NoiseRemove_OpeningFcn, ...
'gui_OutputFcn', @NoiseRemove_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 NoiseRemove is made visible.
function NoiseRemove_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 NoiseRemove (see VARARGIN)
% Choose default command line output for NoiseRemove
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes NoiseRemove wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = NoiseRemove_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)

Universitas Sumatera Utara

LAMPIRAN A-5

% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in cmdLoad.
function cmdLoad_Callback(hObject, eventdata, handles)
% hObject
handle to cmdLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
global S;
%proyek=guidata(gcbo);
[FileName,PathName]=uigetfile({'*.bmp;*.jpg'},' Pilih file citra');
if isequal (FileName,0)
%errordlg('Error ..!','Tidak ada image yang dipilih');
return;
else
S=imread([PathName,FileName]);
lebar=size(S,2);
tinggi=size(S,1);
set (handles.txtNmFile,'string',fullfile(PathName,FileName));
set (handles.txtLebar,'string',num2str(lebar));
set (handles.txtTinggi,'string',num2str(tinggi));
axes(handles.axes1);
imshow(S), title('Citra Asli');
end
% --- Executes on button press in cmdProses.
function cmdProses_Callback(hObject, eventdata, handles)
% hObject
handle to cmdProses (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
global F;
global G;
%global PNoise;
%if isequal (PNoise,0)
%
errordlg('Error ..!','Probabilitas noise belum diinput');
%
return;
%else
%
disp PNoise;
%
errordlg('Ok ..!','Probabilitas noise ok');
[m n]=size(F);
si=1;Q=0;
for i = 1:m
for j = 1:n
con=0; s1=0; s2=0;
for k1 = i-si:i+si
for p1 = j-si:j+si
if ((k1>0 && p1 >0) && (k1