• Tidak ada hasil yang ditemukan

Implementasi Contra Harmonic Mean Filter Untuk Mereduksi Noise Pada Citra Digital

N/A
N/A
Protected

Academic year: 2017

Membagikan "Implementasi Contra Harmonic Mean Filter Untuk Mereduksi Noise Pada Citra Digital"

Copied!
12
0
0

Teks penuh

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

(2)

% 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 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

(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

(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

(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<m && p1<n)) con = con+1;

s1=s1+(F(k1,p1)^Q); s2=s2+(F(k1,p1)^(Q+1)); end

end end

G(i,j)=s2/s1; end

end

axes(handles.axes3);

(6)

%subplot(1,2,2),imshow(b1),title('Cantraharmonic mean filtered');

global S;

[tinggi,lebar]=size(S);

NilaiSSE=sum(sum((double(S)-double(F)).^2)); NilaiMSE=NilaiSSE/tinggi/lebar;

TMSE=NilaiMSE/3;

set(handles.txtMSE,'string',num2str(TMSE)); PSNR = abs(10 * log10( 255 / TMSE));

set(handles.txtPSNR,'string',num2str(PSNR));

% --- Executes on button press in cmdClear.

function cmdClear_Callback(hObject, eventdata, handles) % hObject handle to cmdClear (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

set (handles.txtNmFile,'string',''); set (handles.txtLebar,'string',''); set (handles.txtTinggi,'string',''); set (handles.txtMSE,'string',''); set (handles.txtPSNR,'string',''); axes(handles.axes1);

cla('reset');

axes(handles.axes2); cla('reset');

axes(handles.axes3); cla('reset');

clc;

clear all; clear all; clear all; %close all; clc;

% --- Executes on button press in cmdQuit.

function cmdQuit_Callback(hObject, eventdata, handles) % hObject handle to cmdQuit (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close

% --- Executes on button press in pushbutton5.

function pushbutton5_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 cmdSave.

function cmdSave_Callback(hObject, eventdata, handles) % hObject handle to cmdSave (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global G;

global mmed;

proyek=guidata(gcbo);

[namafile,direktori]=uiputfile({'*.jpg';'*.*'},' Save citra hasil'); if isequal (namafile,0)

(7)

else

set (handles.axes3); %H = uint8(G);

H = uint8(mmed);

%imwrite(G,strcat(direktori,namafile)); imwrite(H,strcat(direktori,namafile)); end

function txtLebar_Callback(hObject, eventdata, handles) % hObject handle to txtLebar (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtLebar as text % str2double(get(hObject,'String')) returns contents of txtLebar as a double

% --- Executes during object creation, after setting all properties. function txtLebar_CreateFcn(hObject, eventdata, handles)

% hObject handle to txtLebar (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white'); end

function txtTinggi_Callback(hObject, eventdata, handles) % hObject handle to txtTinggi (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtTinggi as text % str2double(get(hObject,'String')) returns contents of

txtTinggi as a double

% --- Executes during object creation, after setting all properties. function txtTinggi_CreateFcn(hObject, eventdata, handles)

% hObject handle to txtTinggi (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in cmdNoise.

function cmdNoise_Callback(hObject, eventdata, handles) % hObject handle to cmdNoise (see GCBO)

(8)

% handles structure with handles and user data (see GUIDATA) global F;

global S;

%global PNoise;

%A=str2num(get(handles.edit1, 'string'));

PNoise=str2double(get(handles.txtPNoise,'string')); %F = imnoise(S,'salt & pepper',0.1);

F = imnoise(S,'salt & pepper',PNoise); F = im2double(F);

axes(handles.axes2);

imshow(F), title('Citra Noise');

function txtPNoise_Callback(hObject, eventdata, handles) % hObject handle to txtPNoise (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtPNoise as text % str2double(get(hObject,'String')) returns contents of

txtPNoise as a double

% --- Executes during object creation, after setting all properties. function txtPNoise_CreateFcn(hObject, eventdata, handles)

% hObject handle to txtPNoise (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in cmdProses1.

function cmdProses1_Callback(hObject, eventdata, handles) % hObject handle to cmdProses1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global S;

global F; global mmed;

% membuat matriks dummy I=double(S);

[x,y]=size(I); dummy=zeros(x,y); m=3; n=3;

a=ones(m,n); %Q=-1;

% blok filter for ii=1:x-(m-1) warning off; for jj=1:y-(n-1)

aa=a.*I(ii:m+ii-1,jj:n+jj-1); b=reshape(aa,1,m*n);

b=mean_arit(b,m,n); %b=mean_charm(b,m,n,Q); dummy(ii+1,jj+1)=b; end

(9)

% matriks akhir setelah di filter for ii=2:x-1

for jj=1:y if jj==1

n=I(ii,jj); elseif jj==y n=I(ii,jj); else

n=0; end

mmed(ii-1,jj)=n; end

end

mmed=[I(1,:);mmed;I(x,:)]; mmed=mmed+dummy;

% menampilkan citra grayscale dengan range 0-255

%figure, imshow(mmed,[0 255]); title('Citra Hasil Filter'); %warning on;

axes(handles.axes3);

%imshow(mmed), title('Citra Hasil Noise Remover'); imshow(mmed,[0 255]); title('Citra Hasil Filter');

%Menghitung PSNR

[tinggi,lebar]=size(S);

NilaiSSE=sum(sum((double(S)-double(F)).^2)); NilaiMSE=NilaiSSE/tinggi/lebar;

TMSE=NilaiMSE/3;

set(handles.txtMSE,'string',num2str(TMSE)); PSNR = abs(10 * log10( 255 / TMSE));

set(handles.txtPSNR,'string',num2str(PSNR));

function bb=mean_charm(b,m,n,Q) bb=0;

for i=1:m*n bb=bb+b(i); end

bb1=bb^(Q+1); bb2=bb^(Q);

bb=floor(bb1/bb2);

function bb=mean_arit(b,m,n) bb=0;

for i=1:m*n bb=bb+b(i); end

bb=floor(bb/(m*n));

3. Help

function varargout = Help(varargin) % HELP M-file for Help.fig

% HELP, by itself, creates a new HELP or raises the existing % singleton*.

%

% H = HELP returns the handle to a new HELP or the handle to % the existing singleton*.

(10)

% HELP('CALLBACK',hObject,eventData,handles,...) calls the local

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

%

% HELP('Property','Value',...) creates a new HELP or raises the % existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before Help_OpeningFunction gets called. An

% unrecognized property name or invalid value makes property application

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

% Last Modified by GUIDE v2.5 27-Mar-2014 19:04:11

% Begin initialization code - DO NOT EDIT gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Help_OpeningFcn, ... 'gui_OutputFcn', @Help_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 Help is made visible.

function Help_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 Help (see VARARGIN)

% Choose default command line output for Help handles.output = hObject;

% Update handles structure guidata(hObject, handles);

(11)

% --- Outputs from this function are returned to the command line. function varargout = Help_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 during object creation, after setting all properties. 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

4. About

function varargout = About(varargin) % ABOUT M-file for About.fig

% ABOUT, by itself, creates a new ABOUT or raises the existing % singleton*.

%

% H = ABOUT returns the handle to a new ABOUT or the handle to % the existing singleton*.

%

% ABOUT('CALLBACK',hObject,eventData,handles,...) calls the local

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

%

% ABOUT('Property','Value',...) creates a new ABOUT or raises the

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

% applied to the GUI before About_OpeningFunction gets called. An

% unrecognized property name or invalid value makes property application

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

% Last Modified by GUIDE v2.5 27-Mar-2014 19:04:48

% Begin initialization code - DO NOT EDIT gui_Singleton = 1;

(12)

'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 About is made visible.

function About_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 About (see VARARGIN)

% Choose default command line output for About handles.output = hObject;

% Update handles structure guidata(hObject, handles);

function varargout = About_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;

axes(handles.axes1);

imshow('D:\TA-USU-2014\NITIKA\Program\logoUSU.jpg');

% --- Executes during object creation, after setting all properties. function figure1_CreateFcn(hObject, eventdata, handles)

% hObject handle to figure1 (see GCBO)

Referensi

Dokumen terkait

Setelah berdiskusi siswa diharapkan mampu menyajikan dalam bentuk tulisan tentang perkembangan kerajaan –kerajaan Islam di Jawa.. Setelah berdiskusi siswa diharapkan

Sehubungan dengan itu, Lembaga Penelitian Universitas Negeri Padang bekerjasama dengan Pimpinan Universitas, telah memfasilitasi peneliti untuk melaksanakan penelitian

dalam pasal 11 ayat (1) dilakukan paling lama 1 (satu) bulan sejak diterimanya permohonan pengembalian kelebihan pembayaran pajak sehubungan diterbitkannya Surat

Demikian juga dengan kepemimpinan manajer yang menunjukkan kategori kurang baik dengan persentase 70%.Hasil penelitian ini juga menunjukkan bahwa adanya hubungan yang

Hal itu dipertegas melalui Permendiknas Nomor 41 Tahun 2007 tentang standar proses yang berbunyi perencanaanproses pembelajaran yang mensyaratkan pendidik untuk mengembangkan

yang ditemukan selama pengamatan adalah Gejala serangan Penggerek Batang padi, populasi Wereng hijau dan Walang sangit (lihat gambar 4, 5 dan Lampiran 2), Hasil pengamatan rata

Yohanes Indrayono/Iman Santoso, S.E.. Yohanes Indrayono/Iman

Swasakti Utama Tasikmalaya yang didasarkan pada hasil dari analisis faktor internal dan analisis faktor eksternal juga analisis SWOT yang kemudian datanya digunakan