Vous êtes sur la page 1sur 7

Jawaban Soal UTS Pengolaha Citra Digital

Nama : Ajay Irdan N


NIM : 15164008
Jurusan : Tek.Informatika / TI-5B Sabtu / STT Nusa Putra

1. GUI Perbaikan Citra dan Tampilan Setelah Running

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

% Last Modified by GUIDE v2.5 12-Nov-2017 13:52:39

% Begin initialization code - DO NOT EDIT


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


function UTS_AjayIrdan_TI5B_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 UTS_AjayIrdan_TI5B (see VARARGIN)

% Choose default command line output for UTS_AjayIrdan_TI5B


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = UTS_AjayIrdan_TI5B_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 pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname] = uigetfile({'*.*'});

if ~isequal(filename,0)
Info = imfinfo(fullfile(pathname,filename));
if Info.BitDepth == 1
msgbox('Citra masukan harus citra RGB atau Grayscale');
return
elseif Info.BitDepth == 8
Gambar = imread(fullfile(pathname,filename));
axes(handles.axes1)
cla('reset')
imshow(Gambar)
title('Gambar Asli 8 Bit')
else
Gambar = rgb2gray(imread(fullfile(pathname,filename)));
axes(handles.axes1)
cla('reset')
imshow(Gambar)
title('Gambar Asli RGB')
end
else
return
end

handles.Gambar = Gambar;
guidata(hObject,handles);

set(handles.slider1,'Enable','on')
set(handles.slider1,'Value',1)

set(handles.slider2,'Enable','on')
set(handles.slider2,'Value',0)

set(handles.slider3,'Enable','on')
set(handles.slider4,'Enable','on')

axes(handles.axes2)
cla('reset')
set(gca,'XTick',[])
set(gca,'YTick',[])
axes(handles.axes3)
cla('reset')
set(gca,'XTick',[])
set(gca,'YTick',[])
axes(handles.axes4)
cla('reset')
set(gca,'XTick',[])
set(gca,'YTick',[])

% Here is cheap and easy way to change brightness or contrast in Matlab by percentage.
% 1
%
% newImage = imadjust(originalImage, [a b], [c d]);
%
% Where variables a, b, c and d are between 0 and 1.
%
% To increase contrast: decrease b
% To decrease contrast: increase a
% To increase brightness: increase c
% To decrease brightness: decrease d

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (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 edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a double

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


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (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 edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a double

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


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (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 edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a double

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


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a double

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


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 slider movement.


function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider

nilai_slider1 = get(handles.slider1,'Value');
nilai_slider2 = get(handles.slider2,'Value');
set(handles.edit1,'String',num2str(nilai_slider1))

GambarAsli = handles.Gambar;
GambarKontras = imadjust(GambarAsli, [nilai_slider2 nilai_slider1], [0 1]);

axes(handles.axes2);
imshow(GambarKontras);
title('Gambar Kontras')

axes(handles.axes4)
h = histogram(GambarKontras(:));
xlim([0 255])
grid on
title('Histogram Kontras')

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


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

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
nilai_slider1 = get(handles.slider1,'Value');
nilai_slider2 = get(handles.slider2,'Value');
set(handles.edit2,'String',num2str(nilai_slider2))

GambarAsli = handles.Gambar;
GambarKontras = imadjust(GambarAsli, [nilai_slider2 nilai_slider1], [0 1]);

axes(handles.axes2);
imshow(GambarKontras);
title('Gambar Kontras')

axes(handles.axes4)
h = histogram(GambarKontras(:));
xlim([0 255])
grid on
title('Histogram Kontras')

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


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

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function slider3_Callback(hObject, eventdata, handles)
% hObject handle to slider3 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
ns3 = get(handles.slider3,'Value');
set(handles.edit3,'String',num2str(ns3))

GambarAsli = handles.Gambar;
LowFilter = [ns3 ns3 ns3; ns3 ns3 ns3; ns3 ns3 ns3]/8;
GambarLowFilter = uint8(conv2(double(GambarAsli),LowFilter,'same'));
% filterImage = imadjust(originalImage, [nilai_slider3 nilai_slider1], [0 1]);

axes(handles.axes3);
imshow(GambarLowFilter);
title('Low Pass Filter')

axes(handles.axes4)
h = histogram(GambarLowFilter(:));
xlim([0 255])
grid on
title('Histogram Filter')

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


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

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function slider4_Callback(hObject, eventdata, handles)
% hObject handle to slider4 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
ns4 = get(handles.slider4,'Value');
set(handles.edit4,'String',num2str(ns4))

GambarAsli = handles.Gambar;
HighFilter = [ns4 -2 ns4; -3 ns4 -2; ns4 -2 ns4];
GambarHighFilter = uint8(conv2(double(GambarAsli),HighFilter,'same'));
% filterImage = imadjust(originalImage, [nilai_slider3 nilai_slider1], [0 1]);

axes(handles.axes3);
imshow(GambarHighFilter);
title('High Pass Filter')

axes(handles.axes4)
h = histogram(GambarHighFilter(:));
xlim([0 255])
grid on
title('Histogram Filter')

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


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

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

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


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 slider movement.


function slider5_Callback(hObject, eventdata, handles)
% hObject handle to slider5 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
ns5 = get(handles.slider5,'Value');
set(handles.edit5,'String',num2str(ns5))

GambarAsli = handles.Gambar;
BlockSetting = @(block_struct) ...
std2(block_struct.data) * ones(size(block_struct.data));
GambarBlockProc = blockproc(GambarAsli,[ns5 ns5],BlockSetting);

axes(handles.axes3);
imshow(GambarBlockProc,[]);
title('Block Processing')

axes(handles.axes4)
h = histogram(GambarBlockProc(:));
xlim([0 255])
grid on
title('Histogram Block Proc')

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


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

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
3. Gambar No.3 merupakan gambar asli yang direkayasa menggunakan teknik block processing, hasil
percobaan dengan matlab seperti gambar dibawah ini :

Sintaks Program seperti dibawah ini :

function slider5_Callback(hObject, eventdata, handles)


% hObject handle to slider5 (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
ns5 = get(handles.slider5,'Value');
set(handles.edit5,'String',num2str(ns5))

GambarAsli = handles.Gambar;
BlockSetting = @(block_struct) ...
std2(block_struct.data) * ones(size(block_struct.data));
GambarBlockProc = blockproc(GambarAsli,[ns5 ns5],BlockSetting);

axes(handles.axes3);
imshow(GambarBlockProc,[]);
title('Block Processing')

axes(handles.axes4)
h = histogram(GambarBlockProc(:));
xlim([0 255])
grid on
title('Histogram Block Proc')

Vous aimerez peut-être aussi