• Tidak ada hasil yang ditemukan

Implementasi Dan Perbandingan Metode Geometric Mean Filter Dan Alpha-Trimmed Mean Filter Untuk Mereduksi Exponential Noise Pada Citra Digital

N/A
N/A
Protected

Academic year: 2019

Membagikan "Implementasi Dan Perbandingan Metode Geometric Mean Filter Dan Alpha-Trimmed Mean Filter Untuk Mereduksi Exponential Noise Pada Citra Digital"

Copied!
24
0
0

Teks penuh

(1)

LAMPIRAN A

LISTING PROGRAM

1.

Kode Program Figure Mainform

function varargout = Mainform(varargin) gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @Mainform_OpeningFcn, ... 'gui_OutputFcn', @Mainform_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

function Mainform_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;

guidata(hObject, handles);

function varargout = Mainform_OutputFcn(hObject, eventdata, handles) citra = imread('USU.JPEG');

axes(handles.logo); imshow(citra);

varargout{1} = handles.output;

function about_Callback(hObject, eventdata, handles) About

function help_Callback(hObject, eventdata, handles) Help

function exit_Callback(hObject, eventdata, handles)

pilihan=questdlg(['Do You Want to Exit ?'],['Exit'],'Yes','No','Yes'); if strcmp(pilihan,'No')

return; else

close all end

function reduction1_Callback(hObject, eventdata, handles) Reduction1

(2)

function figure1_DeleteFcn(hObject, eventdata, handles)

function Reduction2_Callback(hObject, eventdata, handles) Reduction2

close(gcbf);

2. Kode Program Figure Menu Reduction Undefined Noise + Exponential Noise

function varargout = Reduction1(varargin) gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @Reduction1_OpeningFcn, ... 'gui_OutputFcn', @Reduction1_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

global runtimeMed;

function Reduction1_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;

guidata(hObject, handles);

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

function mse1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function reduce_noise1_Callback(hObject, eventdata, handles) global runtimeMed;

runtimeMed = cputime;

Citraasal = getimage(handles.axes1); A= getimage(handles.axes2);

hObject = waitbar(0,'1','Name','Processing'); for step = 1:1000

waitbar(step/1000,hObject,sprintf('Processing...')) end

(3)

ukuran=3;

B=geometric(A,ukuran); axes(handles.axes3); imshow(B)

runtimeMed=cputime-runtimeMed;

Citrahasil= getimage(handles.axes3);

[NilaiMSE PSNR]=HitungMSE(Citraasal,Citrahasil); set(handles.mse1,'String',NilaiMSE);

set(handles.psnr1,'String',PSNR);

set(handles.runtime1,'String',runtimeMed); set(handles.save1,'Enable','on');

function save1_Callback(hObject, eventdata, handles)

[nama_file,nama_path] = uiputfile({'*.bmp';'*.*'},'Save Image'); if isequal([nama_file,nama_path],[0,0]);

return else

citra = getimage(handles.axes3);

imwrite(citra,strcat(nama_path,nama_file)); warndlg('Succes save file','Warning')

end

function generate_noise1_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu1,'Value');

switch indeks case 1

a = helpdlg('Please choose noise probability'); case 2

a = 0.01; case 3

a = 0.02; case 4

a = 0.03; case 5

a = 0.04; case 6

a = 0.05; end

handles.a=a;

a=handles.a;

if (0.05>=a>=0.01)

A = getimage(handles.axes1); B=double(A);

[m,n] = size(A); for i = 1:m for j = 1:n

noise = -1/a*log(1-rand); B(i,j) = round(A(i,j)+noise); if B(i,j) > 255

B(i,j) = 255; end

(4)

B=uint8(B);

axes(handles.axes2); imshow(B)

set(handles.reduce_noise1,'Enable','on'); end

function browse_Callback(hObject, eventdata, handles)

[nama_file,nama_path]=uigetfile({'*.bmp','Image File(*.bmp)'},'Browse Image');

if ~isequal(nama_file,0)

info = imfinfo([nama_path, nama_file]); lokasi = info.Filename

ukuran_file = info.FileSize/1024 height = info.Height;

width = info.Width;

handles.citra=imread(fullfile(nama_path,nama_file)); guidata(hObject,handles);

axes(handles.axes1); imshow(handles.citra);

set(handles.lokasi1, 'String', lokasi);

set(handles.ukuran_file1, 'String', ukuran_file); set(handles.dimensi1,'String',width);

set(handles.dimensi2,'String',height); set(handles.nama_file1,'String',nama_file); set(handles.generate_noise1,'Enable','on'); else

return end;

function reset_all_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

guidata(hObject,handles); axes(handles.axes1); imshow(handles.citra); axes(handles.axes2); imshow(handles.citra); axes(handles.axes3); imshow(handles.citra); axes(handles.axes4); imshow(handles.citra); axes(handles.axes5); imshow(handles.citra); axes(handles.axes6); imshow(handles.citra);

set(handles.dimensi1,'string',''); set(handles.dimensi2,'string',''); set(handles.nama_file1,'string',''); set(handles.lokasi1,'string',''); set(handles.ukuran_file1,'string',''); set(handles.mse1,'string','');

set(handles.psnr1,'string',''); set(handles.runtime1,'string','');

(5)

set(handles.dimensi3,'string',''); set(handles.dimensi4,'string',''); set(handles.nama_file2,'string',''); set(handles.lokasi2,'string',''); set(handles.ukuran_file2,'string',''); set(handles.mse2,'string','');

set(handles.psnr2,'string',''); set(handles.runtime2,'string','');

set(handles.generate_noise2,'Enable','off'); set(handles.reduce_noise2,'Enable','off'); set(handles.save2,'Enable','off');

set(handles.popupmenu1,'Value',1); set(handles.popupmenu2,'Value',1); set(handles.popupmenu3,'Value',1);

function back_Callback(hObject, eventdata, handles)

pilihan=questdlg(['Back to Main Menu ?'],['Exit'],'Yes','No','Yes'); if strcmp(pilihan,'No')

return; else

close(gcbf); Mainform; end

function back_CreateFcn(hObject, eventdata, handles)

function dimensi2_Callback(hObject, eventdata, handles)

function dimensi2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function nama_file1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function psnr1_Callback(hObject, eventdata, handles)

function psnr1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function dimensi1_Callback(hObject, eventdata, handles)

(6)

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

function lokasi1_Callback(hObject, eventdata, handles)

function lokasi1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function ukuran_file1_Callback(hObject, eventdata, handles)

function ukuran_file1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function popupmenu1_Callback(hObject, eventdata, handles)

function popupmenu1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function reset_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

guidata(hObject,handles); axes(handles.axes1); imshow(handles.citra); axes(handles.axes2); imshow(handles.citra); axes(handles.axes3); imshow(handles.citra);

set(handles.dimensi1,'string',''); set(handles.dimensi2,'string',''); set(handles.nama_file1,'string',''); set(handles.lokasi1,'string',''); set(handles.ukuran_file1,'string',''); set(handles.mse1,'string','');

set(handles.psnr1,'string',''); set(handles.runtime1,'string','');

set(handles.generate_noise1,'Enable','off'); set(handles.reduce_noise1,'Enable','off'); set(handles.save1,'Enable','off');

set(handles.popupmenu1,'Value',1)

function runtime1_Callback(hObject, eventdata, handles)

(7)

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

function dimensi3_Callback(hObject, eventdata, handles)

function dimensi3_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function browse2_Callback(hObject, eventdata, handles)

[nama_file,nama_path]=uigetfile({'*.bmp','Image File(*.bmp)'},'Browse Image');

if ~isequal(nama_file,0)

info = imfinfo([nama_path, nama_file]); lokasi = info.Filename

ukuran_file = info.FileSize/1024 height = info.Height;

width = info.Width;

handles.citra=imread(fullfile(nama_path,nama_file)); guidata(hObject,handles);

axes(handles.axes4); imshow(handles.citra);

set(handles.lokasi2, 'String', lokasi);

set(handles.ukuran_file2, 'String', ukuran_file); set(handles.dimensi3,'String',width);

set(handles.dimensi4,'String',height); set(handles.nama_file2,'String',nama_file); set(handles.generate_noise2,'Enable','on'); else

return end;

function dimensi4_Callback(hObject, eventdata, handles)

function dimensi4_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function nama_file2_Callback(hObject, eventdata, handles)

function nama_file2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function lokasi2_Callback(hObject, eventdata, handles)

(8)

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

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

function ukuran_file2_Callback(hObject, eventdata, handles)

function ukuran_file2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function runtime2_Callback(hObject, eventdata, handles)

function runtime2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function mse2_Callback(hObject, eventdata, handles)

function mse2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function reduce_noise2_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu3,'Value');

switch indeks case 1

d = helpdlg('Please choose value of d'); case 2

d = 0; case 3 d = 1; case 4 d = 2; case 5 d = 3; case 6 d = 4; case 7 d = 5; case 8 d = 6; case 9 d = 7; case 10 d = 8; end

(9)

global runtimeMed; runtimeMed = cputime; if (8>=d>=1)

Citraasal = getimage(handles.axes4); A= getimage(handles.axes5);

hObject = waitbar(0,'1','Name','Processing'); for step = 1:1000

waitbar(step/1000,hObject,sprintf('Processing...')) end

delete(hObject)

ukuran =3; d = handles.d;

B=alphatrimmed(A,ukuran,d);

B=uint8(B);

axes(handles.axes6); imshow(B)

runtimeMed=cputime-runtimeMed;

Citrahasil= getimage(handles.axes6);

[NilaiMSE PSNR]=HitungMSE(Citraasal,Citrahasil); set(handles.mse2,'String',NilaiMSE);

set(handles.psnr2,'String',PSNR);

set(handles.runtime2,'String',runtimeMed); set(handles.save2,'Enable','on');

end

function save2_Callback(hObject, eventdata, handles)

[nama_file,nama_path] = uiputfile({'*.bmp';'*.*'},'Save Image'); if isequal([nama_file,nama_path],[0,0]);

return else

citra = getimage(handles.axes6);

imwrite(citra,strcat(nama_path,nama_file)); warndlg('Success save file','Warning') end

function psnr2_Callback(hObject, eventdata, handles)

function psnr2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function popupmenu2_Callback(hObject, eventdata, handles)

function popupmenu2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

(10)

end

function generate_noise2_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu2,'Value');

switch indeks case 1

a = helpdlg('Please choose noise probability'); case 2

a = 0.01; case 3

a = 0.02; case 4

a = 0.03; case 5

a = 0.04; case 6

a = 0.05; end

handles.aa=a;

a=handles.aa; if (0.05>=a>=0.01)

A = getimage(handles.axes4); B=double(A);

[m,n] = size(A); for i = 1:m for j = 1:n

noise = -1/a*log(1-rand); B(i,j) = round(A(i,j)+ noise); if B(i,j) > 255

B(i,j) = 255; end

end end B=uint8(B);

axes(handles.axes5); imshow(B)

set(handles.reduce_noise2,'Enable','on'); end

function popupmenu3_Callback(hObject, eventdata, handles)

function popupmenu3_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function mse1_Callback(hObject, eventdata, handles)

function nama_file1_Callback(hObject, eventdata, handles)

function reset2_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

(11)

axes(handles.axes4); imshow(handles.citra); axes(handles.axes5); imshow(handles.citra); axes(handles.axes6); imshow(handles.citra);

set(handles.dimensi3,'string',''); set(handles.dimensi4,'string',''); set(handles.nama_file2,'string',''); set(handles.lokasi2,'string',''); set(handles.ukuran_file2,'string',''); set(handles.mse2,'string','');

set(handles.psnr2,'string',''); set(handles.runtime2,'string','');

set(handles.generate_noise2,'Enable','off'); set(handles.reduce_noise2,'Enable','off'); set(handles.save2,'Enable','off');

set(handles.popupmenu2,'Value',1) set(handles.popupmenu3,'Value',1)

3.

Kode Program Figure Menu Reduction Exponential Noise

function varargout = Reduction2(varargin) gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @Reduction2_OpeningFcn, ... 'gui_OutputFcn', @Reduction2_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

global runtimeMed;

function Reduction2_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;

guidata(hObject, handles);

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

function mse1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

(12)

function reduce_noise1_Callback(hObject, eventdata, handles) global runtimeMed;

runtimeMed = cputime;

Citraasal = getimage(handles.axes1); A= getimage(handles.axes2);

hObject = waitbar(0,'1','Name','Processing'); for step = 1:1000

waitbar(step/1000,hObject,sprintf('Processing...')) end

delete(hObject)

ukuran=3;

B=geometric(A,ukuran); axes(handles.axes3); imshow(B)

runtimeMed=cputime-runtimeMed;

Citrahasil= getimage(handles.axes3);

[NilaiMSE PSNR]=HitungMSE(Citraasal,Citrahasil); set(handles.mse1,'String',NilaiMSE);

set(handles.psnr1,'String',PSNR);

set(handles.runtime1,'String',runtimeMed); set(handles.save1,'Enable','on');

function save1_Callback(hObject, eventdata, handles)

[nama_file,nama_path] = uiputfile({'*.bmp';'*.*'},'Save Image'); if isequal([nama_file,nama_path],[0,0]);

return else

citra = getimage(handles.axes3);

imwrite(citra,strcat(nama_path,nama_file)); warndlg('Succes save file','Warning')

end

function generate_noise1_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu1,'Value');

switch indeks case 1

a = helpdlg('Please choose noise probability'); case 2

a = 0.01; case 3

a = 0.02; case 4

a = 0.03; case 5

a = 0.04; case 6

a = 0.05; end

handles.a=a;

(13)

if (0.05>=a>=0.01)

A = getimage(handles.axes1); B=double(A);

[m,n] = size(A); for i = 1:m for j = 1:n

noise = -1/a*log(1-rand); B(i,j) = round(A(i,j)+noise); if B(i,j) > 255

B(i,j) = 255; end

end end B=uint8(B);

axes(handles.axes2); imshow(B)

set(handles.reduce_noise1,'Enable','on'); end

function browse_Callback(hObject, eventdata, handles)

[nama_file,nama_path]=uigetfile({'*.bmp','Image File(*.bmp)'},'Browse Image');

if ~isequal(nama_file,0)

info = imfinfo([nama_path, nama_file]); lokasi = info.Filename

ukuran_file = info.FileSize/1024 height = info.Height;

width = info.Width;

handles.citra=imread(fullfile(nama_path,nama_file)); guidata(hObject,handles);

axes(handles.axes1); imshow(handles.citra);

set(handles.lokasi1, 'String', lokasi);

set(handles.ukuran_file1, 'String', ukuran_file); set(handles.dimensi1,'String',width);

set(handles.dimensi2,'String',height); set(handles.nama_file1,'String',nama_file); set(handles.generate_noise1,'Enable','on'); else

return end;

function reset_all_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

(14)

axes(handles.axes6); imshow(handles.citra);

set(handles.dimensi1,'string',''); set(handles.dimensi2,'string',''); set(handles.nama_file1,'string',''); set(handles.lokasi1,'string',''); set(handles.ukuran_file1,'string',''); set(handles.mse1,'string','');

set(handles.psnr1,'string',''); set(handles.runtime1,'string','');

set(handles.generate_noise1,'Enable','off'); set(handles.reduce_noise1,'Enable','off'); set(handles.save1,'Enable','off');

set(handles.dimensi3,'string',''); set(handles.dimensi4,'string',''); set(handles.nama_file2,'string',''); set(handles.lokasi2,'string',''); set(handles.ukuran_file2,'string',''); set(handles.mse2,'string','');

set(handles.psnr2,'string',''); set(handles.runtime2,'string','');

set(handles.generate_noise2,'Enable','off'); set(handles.reduce_noise2,'Enable','off'); set(handles.save2,'Enable','off');

set(handles.popupmenu1,'Value',1); set(handles.popupmenu2,'Value',1); set(handles.popupmenu3,'Value',1);

function back_Callback(hObject, eventdata, handles)

pilihan=questdlg(['Back to Main Menu ?'],['Exit'],'Yes','No','Yes'); if strcmp(pilihan,'No')

return; else

close(gcbf); Mainform; end

function back_CreateFcn(hObject, eventdata, handles)

function dimensi2_Callback(hObject, eventdata, handles)

function dimensi2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function nama_file1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

(15)

function psnr1_Callback(hObject, eventdata, handles)

function psnr1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function dimensi1_Callback(hObject, eventdata, handles)

function dimensi1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function lokasi1_Callback(hObject, eventdata, handles)

function lokasi1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function ukuran_file1_Callback(hObject, eventdata, handles)

function ukuran_file1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function popupmenu1_Callback(hObject, eventdata, handles)

function popupmenu1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function reset_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

guidata(hObject,handles); axes(handles.axes1); imshow(handles.citra); axes(handles.axes2); imshow(handles.citra); axes(handles.axes3); imshow(handles.citra);

(16)

set(handles.mse1,'string',''); set(handles.psnr1,'string',''); set(handles.runtime1,'string','');

set(handles.generate_noise1,'Enable','off'); set(handles.reduce_noise1,'Enable','off'); set(handles.save1,'Enable','off');

set(handles.popupmenu1,'Value',1)

function runtime1_Callback(hObject, eventdata, handles)

function runtime1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function dimensi3_Callback(hObject, eventdata, handles)

function dimensi3_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function browse2_Callback(hObject, eventdata, handles)

[nama_file,nama_path]=uigetfile({'*.bmp','Image File(*.bmp)'},'Browse Image');

if ~isequal(nama_file,0)

info = imfinfo([nama_path, nama_file]); lokasi = info.Filename

ukuran_file = info.FileSize/1024 height = info.Height;

width = info.Width;

handles.citra=imread(fullfile(nama_path,nama_file)); guidata(hObject,handles);

axes(handles.axes4); imshow(handles.citra);

set(handles.lokasi2, 'String', lokasi);

set(handles.ukuran_file2, 'String', ukuran_file); set(handles.dimensi3,'String',width);

set(handles.dimensi4,'String',height); set(handles.nama_file2,'String',nama_file); set(handles.generate_noise2,'Enable','on'); else

return end;

function dimensi4_Callback(hObject, eventdata, handles)

function dimensi4_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

(17)

function nama_file2_Callback(hObject, eventdata, handles)

function nama_file2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function lokasi2_Callback(hObject, eventdata, handles)

function lokasi2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function ukuran_file2_Callback(hObject, eventdata, handles)

function ukuran_file2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function runtime2_Callback(hObject, eventdata, handles)

function runtime2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function mse2_Callback(hObject, eventdata, handles)

function mse2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function reduce_noise2_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu3,'Value');

switch indeks case 1

d = helpdlg('Please choose value of d'); case 2

(18)

case 6 d = 4; case 7 d = 5; case 8 d = 6; case 9 d = 7; case 10 d = 8; end

handles.d=d;

global runtimeMed; runtimeMed = cputime; if (8>=d>=1)

Citraasal = getimage(handles.axes4); A= getimage(handles.axes5);

hObject = waitbar(0,'1','Name','Processing'); for step = 1:1000

waitbar(step/1000,hObject,sprintf('Processing...')) end

delete(hObject)

ukuran =3; d = handles.d;

B=alphatrimmed(A,ukuran,d);

B=uint8(B);

axes(handles.axes6); imshow(B)

runtimeMed=cputime-runtimeMed;

Citrahasil= getimage(handles.axes6);

[NilaiMSE PSNR]=HitungMSE(Citraasal,Citrahasil); set(handles.mse2,'String',NilaiMSE);

set(handles.psnr2,'String',PSNR);

set(handles.runtime2,'String',runtimeMed); set(handles.save2,'Enable','on');

end

function save2_Callback(hObject, eventdata, handles)

[nama_file,nama_path] = uiputfile({'*.bmp';'*.*'},'Save Image'); if isequal([nama_file,nama_path],[0,0]);

return else

citra = getimage(handles.axes6);

imwrite(citra,strcat(nama_path,nama_file)); warndlg('Success save file','Warning') end

(19)

function psnr2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function popupmenu2_Callback(hObject, eventdata, handles)

function popupmenu2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function generate_noise2_Callback(hObject, eventdata, handles) indeks=get(handles.popupmenu2,'Value');

switch indeks case 1

a = helpdlg('Please choose noise probability'); case 2

a = 0.01; case 3

a = 0.02; case 4

a = 0.03; case 5

a = 0.04; case 6

a = 0.05; end

handles.aa=a;

a=handles.aa; if (0.05>=a>=0.01)

A = getimage(handles.axes4); B=double(A);

[m,n] = size(A); for i = 1:m for j = 1:n

noise = -1/a*log(1-rand); B(i,j) = round(A(i,j)+ noise); if B(i,j) > 255

B(i,j) = 255; end

end end B=uint8(B);

axes(handles.axes5); imshow(B)

set(handles.reduce_noise2,'Enable','on'); end

function popupmenu3_Callback(hObject, eventdata, handles)

(20)

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

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

function mse1_Callback(hObject, eventdata, handles)

function nama_file1_Callback(hObject, eventdata, handles)

function reset2_Callback(hObject, eventdata, handles) handles.citra = handles.reset;

guidata(hObject,handles); axes(handles.axes4); imshow(handles.citra); axes(handles.axes5); imshow(handles.citra); axes(handles.axes6); imshow(handles.citra);

set(handles.dimensi3,'string',''); set(handles.dimensi4,'string',''); set(handles.nama_file2,'string',''); set(handles.lokasi2,'string',''); set(handles.ukuran_file2,'string',''); set(handles.mse2,'string','');

set(handles.psnr2,'string',''); set(handles.runtime2,'string','');

set(handles.generate_noise2,'Enable','off'); set(handles.reduce_noise2,'Enable','off'); set(handles.save2,'Enable','off');

set(handles.popupmenu2,'Value',1) set(handles.popupmenu3,'Value',1)

4.

Kode Program Figure Help

function varargout = Help(varargin) 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

function Help_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;

(21)

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

function figure1_ResizeFcn(hObject, eventdata, handles)

function listbox2_Callback(hObject, eventdata, handles)

function listbox2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function listbox4_Callback(hObject, eventdata, handles) function listbox4_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function listbox5_Callback(hObject, eventdata, handles)

function listbox5_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function home_Callback(hObject, eventdata, handles)

function home_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function listbox7_Callback(hObject, eventdata, handles)

function listbox7_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

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

function reduction1_Callback(hObject, eventdata, handles)

function reduction1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

(22)

function reduction2_Callback(hObject, eventdata, handles)

function reduction2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function close_Callback(hObject, eventdata, handles) close

5.

Kode Program Figure About

function varargout = About(varargin) gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @About_OpeningFcn, ... 'gui_OutputFcn', @About_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

function About_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;

guidata(hObject, handles);

function varargout = About_OutputFcn(hObject, eventdata, handles) citra = imread('Liza.JPG');

axes(handles.programmer); imshow(citra);

varargout{1} = handles.output;

function figure1_ResizeFcn(hObject, eventdata, handles)

function pushbutton1_Callback(hObject, eventdata, handles) close

6.

Kode Program Function Geometric Mean Filter

function [B] = geometric(A,ukuran) if nargin < 2

(23)

[m,n] =size(A);

cons = floor(ukuran/2); A=double(A);

B=double(A);

for i=1+cons : m-cons for j=1+cons : n-cons jumlah = 1;

for p = -cons : cons for q= -cons : cons

jumlah = jumlah * A(i+p, j+q); end

end

B(i, j) = jumlah ^ (1/(ukuran * ukuran)); end

end

B=uint8(B);

7.

Kode Program Function Alpha-Trimmed Mean Filter

function [B] = alphatrimmed(A, ukuran, d) if nargin < 2

ukuran = 3; end

if nargin < 3 d = handles.d; end

[m, n] = size(A);

cons = floor(ukuran / 2); A = double(A);

B = double(A);

Nilai = zeros(1,ukuran * ukuran);

for i=1+cons : m-cons for j=1+cons: n-cons index = 1;

for p = -cons : cons for q = -cons : cons

Nilai(index) = A(i+p, j+q); index = index + 1;

end end

index = index - 1; % jumlah data

% Urutkan data pada array nilai for p = 2:index

x = Nilai(p);

% Sisipkan x ke dalam data[1..p-1] q = p - 1;

(24)

while ((q >= 1) && (~ketemu)) if (x < Nilai(q))

Nilai(q+1) = Nilai(q); q = q - 1;

else

ketemu = 1; end

Nilai(q+1) = x; end

end

if (d==0)

B(i, j) = sum(Nilai(2:8)) * (1/((ukuran*ukuran)-d)); elseif (d == 1||d == 2||d== 3||d==4||d==5||d==6||d==7) B(i, j) = sum(Nilai(2:8)) * (1/((ukuran*ukuran)-d)); elseif (d==8)

B(i, j) = Nilai(floor(ukuran * ukuran/2) + 1); end

end end

B = uint8(B);

8.

Kode Program Function MSE & PSNR

function [NilaiMSE PSNR] = HitungMSE(Citraasal,Citrahasil) a = double(Citraasal);

b = double(Citrahasil); NilaiMSE=(a-b).^2;

[tinggi lebar]= size(Citraasal);

NilaiMSE=(sum(NilaiMSE(:))/(tinggi*lebar)); PSNR = 20*log10(255/sqrt(NilaiMSE));

Referensi

Dokumen terkait

metode GMF dan ATMF untuk reduksi undefined noise + exponential noise dengan reduksi exponential noise pada citra berkontras terang. dapat dilihat pada

function waktu_CreateFcn(hObject, eventdata, handles) if ispc &amp;&amp; isequal(get(hObject,'BackgroundColor'),

function edit3_CreateFcn(hObject, eventdata, handles) if ispc &amp;&amp; isequal(get(hObject,'BackgroundColor'),

Hasil penelitian pada reduksi undefined noise ditambah exponential noise maupun pada reduksi hanya exponential noise menunjukkan nilai MSE lebih kecil dan nilai PSNR

function filter_Callback(hObject, eventdata, handles) function menuAbout_Callback(hObject, eventdata, handles)

function total_CreateFcn(hObject, eventdata, handles) if ispc &amp;&amp; isequal(get(hObject,'BackgroundColor'),

function edit_MSE1_CreateFcn(hObject, eventdata, handles) if ispc &amp;&amp; isequal(get(hObject,'BackgroundColor'),. get(0,'defaultUicontrolBackgroundColor'))

function deviden_Callback(hObject, eventdata, handles) function deviden_CreateFcn(hObject, eventdata, handles) if ispc &amp;&amp; isequal(get(hObject,'BackgroundColor'),