Citra GUI

Mengubah kode program pada contoh axes,dengan menambahkan dua buah tombol, untuk Citra Negatif dan Citra Grayscale. Jika tombol ini diklik, maka citra yang tampil dalam axes akan berubah menjadi grayslace atau negatif. Sehingga program mempunyai 3 tombol: untuk brightness, negatif dan grayscale
&nsbp;
Berikut caranya:
1. Buka GUIDE matlab, lalu rancang tampilan GUIDE Matlab seperti gambar di bawah ini:
 

gui


2. Untuk Property Inspector, Ubah menjadi:
 

No.Objek Type Property Value
1. Axes Tag axes_citra
    XTick [] (dikosongkan)
    YTick [] (dikosongkan)
2. Static Text String Input Nilai
3. Edit Text Tag input_nilai
    String [] (dikosongkan)
4. Push Button Tag brightness
    String Brightness
5. Push Button Tag negatif
    String Negatif
6. Push Button Tag grayscale
    String Grayscale

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

% Last Modified by GUIDE v2.5 09-Jan-2013 12:39:25

% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @gui_tugas_OpeningFcn, …
‘gui_OutputFcn’, @gui_tugas_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 gui_tugas is made visible.
function gui_tugas_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 gui_tugas (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui_tugas wait for user response (see UIRESUME)
% uiwait(handles.figure1);

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

function input_nilai_Callback(hObject, eventdata, handles)
% hObject handle to input_nilai (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 input_nilai as text
% str2double(get(hObject,’String’)) returns contents of input_nilai as a double

% — Executes during object creation, after setting all properties.
function input_nilai_CreateFcn(hObject, eventdata, handles)
% hObject handle to input_nilai (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 brightness.
function brightness_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread(‘bunga1.jpg’);
citra_hasil=double(citra_asli);
nilai_brightness=str2num(get(handles.input_nilai,’String’));
citra_hasil=citra_hasil+nilai_brightness;
citra_hasil=uint8(citra_hasil);
axes(handles.axes_citra);
imshow(citra_hasil);

% hObject handle to brightness (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 negatif.
function negatif_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread(‘bunga1.jpg’);
citra_hasil=double(citra_asli);
citra_hasil=255-citra_asli;
citra_hasil=uint8(citra_hasil);
axes(handles.axes_citra);
imshow(citra_hasil);

% hObject handle to negatif (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 grayscale.
function grayscale_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread(‘bunga1.jpg’);
citra_hasil=double(citra_asli);
citra_hasil=rgb2gray(citra_asli);
axes(handles.axes_citra);
imshow(citra_hasil);

% hObject handle to grayscale (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

 

Output
 
Gambar Brightness:

gui1

 
Gambar Negatif
 gui2
 
Gambar Grayscale:
gui3