Beranda > Matlab, Sinaung > Aplikasi GUI Matlab untuk Image processing

Aplikasi GUI Matlab untuk Image processing


Matlab adalah salah satu software pengolahan citra yang cukup handal dan praktis.

berikut contoh program sederhananya:

ketikkan MFile berikut pada text editor kemudian simpan dengan extensi .m

(programGUICitra.m)

%//=============================

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

% Last Modified by GUIDE v2.5 07-Jan-2010 06:24:16

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

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

% Update handles structure
guidata(hObject, handles);

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

% — Outputs from this function are returned to the command line.
function varargout = programGUICitra_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 file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% ——————————————————————–
function buka_Callback(hObject, eventdata, handles)
% hObject    handle to buka (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
[namafile,direktori]=uigetfile({‘*.jpg’;’*.*’},’Buka Citra’);
I=imread(strcat(direktori,namafile));
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(I));
set(proyek.axes1,’Userdata’,I);
set(proyek.figure1,’Userdata’,I);
%set(proyek.ebit,’String’,info.BitDept);

% ——————————————————————–
function simpan_Callback(hObject, eventdata, handles)
% hObject    handle to simpan (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
[namafile,direktori]=uiputfile({‘*.jpg’;’*.*’},’Simpan Citra’);
I=get(proyek.axes1,’Userdata’);
imwrite(I,strcat(direktori,namafile));
% ——————————————————————–
function tutup_Callback(hObject, eventdata, handles)
% hObject    handle to tutup (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla;

% ——————————————————————–
function aturhalaman_Callback(hObject, eventdata, handles)
% hObject    handle to aturhalaman (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pagesetupdlg;

% ——————————————————————–
function preview_Callback(hObject, eventdata, handles)
% hObject    handle to preview (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printpreview;

% ——————————————————————–
function cetak_Callback(hObject, eventdata, handles)
% hObject    handle to cetak (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg;

% ——————————————————————–
function keluar_Callback(hObject, eventdata, handles)
% hObject    handle to keluar (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;

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

% ——————————————————————–
function crop_Callback(hObject, eventdata, handles)
% hObject    handle to crop (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
imcrop;

% ——————————————————————–
function reset_Callback(hObject, eventdata, handles)
% hObject    handle to reset (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.figure1,’Userdata’);
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(I));
set(proyek.axes1,’Userdata’,I);

% ——————————————————————–
function uimshow_Callback(hObject, eventdata, handles)
% hObject    handle to uimshow (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
figure;
set(imshow(I));

% ——————————————————————–
function uimview_Callback(hObject, eventdata, handles)
% hObject    handle to uimview (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
figure;
set(imview(I));

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

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

% ——————————————————————–
function zoom_on_Callback(hObject, eventdata, handles)
% hObject    handle to zoom_on (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
zoom on;

% ——————————————————————–
function zoom_off_Callback(hObject, eventdata, handles)
% hObject    handle to zoom_off (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
zoom off;

% ——————————————————————–
function rotasi_Callback(hObject, eventdata, handles)
% hObject    handle to rotasi (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=imrotate(I,90,’bilinear’);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function grayscale_Callback(hObject, eventdata, handles)
% 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)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=rgb2gray(I);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function histogram_Callback(hObject, eventdata, handles)
% hObject    handle to histogram (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
figure;
subplot(1,1,1),imhist(I);title(‘Histogram’);

% ——————————————————————–
function ekualisasi_Callback(hObject, eventdata, handles)
% hObject    handle to ekualisasi (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=histeq(I);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

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

% ——————————————————————–
function average_Callback(hObject, eventdata, handles)
% hObject    handle to average (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=filter2(fspecial(‘average’,3),I)/255;
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function median_Callback(hObject, eventdata, handles)
% hObject    handle to median (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=medfilt2(I,[3 3]);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function wiener_Callback(hObject, eventdata, handles)
% hObject    handle to wiener (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
A=wiener2(I,[3 3]);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

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

% ——————————————————————–
function prewit_Callback(hObject, eventdata, handles)
% hObject    handle to prewit (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
metodeEdge=’prewit’;
A=edge(I,metodeEdge);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function canny_Callback(hObject, eventdata, handles)
% hObject    handle to canny (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
metodeEdge=’canny’;
A=edge(I,metodeEdge);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function sobel_Callback(hObject, eventdata, handles)
% hObject    handle to sobel (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
metodeEdge=’sobel’;
A=edge(I,metodeEdge);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

% ——————————————————————–
function roberts_Callback(hObject, eventdata, handles)
% hObject    handle to roberts (see GCBO)
% eventdata  reserved – to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.axes1,’Userdata’);
metodeEdge=’roberts’;
A=edge(I,metodeEdge);
cla;
set(proyek.figure1,’CurrentAxes’,proyek.axes1);
set(imshow(A));
set(proyek.axes1,’Userdata’,A);

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

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

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

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

%//=============================

tapi sebelum itu desain tampilan GUI sesuai kebutuhan.

untuk resource lengkapnya silakan download di sini

selamat mencoba, semoga bermanfaat.

Kategori:Matlab, Sinaung
  1. yosi
    Juli 22, 2010 pukul 2:19 pm

    mas mau tanya fungsi pada matlab yg
    proyek=guidata(gcbo);
    itu buat apa ya?

  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: