CATATULANG

Materi Kuliah Teknik Informatika

Menghitung Region Property Suatu Citra Yang di Akuisisi Dari Webcam


Didalam prorgam region property ini akan di cari property dari suatu citra. Property yang di cari adalah : luas, panjang, lebar dan rasio. Kita akan menggunakan citra yang di ambil dari webcam (baca : Menggunakan Webcam di Matlab Untuk Proses Akuisisi Citra Digital).

File GUIDE Matlab untuk akuisisi citra digital dapat diperoleh melalui halaman berikut ini: Source Code
Sedangkan tampilan source codenya adalah:
function varargout = RegionProperty(varargin)
% REGIONPROPERTY MATLAB code for RegionProperty.fig
%      REGIONPROPERTY, by itself, creates a new REGIONPROPERTY or raises the existing
%      singleton*.
%
%      H = REGIONPROPERTY returns the handle to a new REGIONPROPERTY or the handle to
%      the existing singleton*.
%
%      REGIONPROPERTY('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in REGIONPROPERTY.M with the given input arguments.
%
%      REGIONPROPERTY('Property','Value',...) creates a new REGIONPROPERTY or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before RegionProperty_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to RegionProperty_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 RegionProperty

% Last Modified by GUIDE v2.5 22-Oct-2018 08:44:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @RegionProperty_OpeningFcn, ...
                   'gui_OutputFcn',  @RegionProperty_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 RegionProperty is made visible.
function RegionProperty_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 RegionProperty (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = RegionProperty_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 pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
IAHI = imaqhwinfo;
IA = (IAHI.InstalledAdaptors);
D = menu('Select Video Input Device:',IA);
 
if isempty(IA)||D==0
    msgbox({'You don''t have any VideoInput Installed Adaptors!',...
        'Please! try again and select Adaptor properly.'})
    return
end
 
IA = char(IA);
IA = IA(D,:);
IA(IA==' ')=[];
x = imaqhwinfo(IA);
 
try
    DeviceID = menu('Select Device ID',x.DeviceIDs);
    F = x.DeviceInfo(DeviceID).SupportedFormats;
    nF = menu('Select FORMAT',F);
    Format = F{nF};
catch
    warndlg({'Try Another Device or ID ';...
        'You Don''t Have Installed This Device (VideoInputDevice)'})
    return
end
 
VidObj = videoinput(IA, DeviceID, Format);
handles.VidObj = VidObj;
vidRes = get(handles.VidObj, 'VideoResolution');
nBands = get(handles.VidObj, 'NumberOfBands');
axes(handles.axes1)
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
preview(handles.VidObj, hImage)
set(VidObj,'returnedcolorspace','rgb');
guidata(hObject, handles);
 
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
    VidObj = handles.VidObj;
    i = getsnapshot(VidObj);
    axes(handles.axes2)
    imshow(i);
     
    imwrite(i,strcat(['zivi.jpg']))
catch
end


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    VidObj = handles.VidObj;
    i = getsnapshot(VidObj);
    axes(handles.axes2)
    imshow(i);
     
    imwrite(i,strcat(['zivi.jpg']))
catch
end


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    delete(handles.VidObj)
catch
end
 
axes(handles.axes1)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])
 
axes(handles.axes2)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])

axes(handles.axes3)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])
 
set(handles.edit1,'String',0)
set(handles.edit2,'String',0)
set(handles.edit3,'String',0)
set(handles.edit4,'String',0)


% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data = imread('zivi.jpg');

R=data(:,:,1);
G=data(:,:,2);
B=data(:,:,3);

Y=0.3333*R+0.3333*G+0.3333*B;

imshow(Y);
[m, n]=size(Y);
for i=1:m,
    for j=1:n,
        if(Y(i,j) > 120)
            Y(i,j)=1;
        else
            Y(i,j)=0;
        end;
    end,
end,
Y1=double(Y);
luas=0;
for i=1:m,
    for j=1:n,
        luas=luas+(Y1(i,j));
    end,
end,
luas;
P=[];
L=[];
for i=1:m,
    for j=1:n,
        if (Y(i,j)==1)
            P=[P i];
            L=[L j];
        end,
    end,
end,
P = max(P)- min(P);
L = max(L)- min(L);
rasio = P/L;
    
set(handles.edit1,'String',num2str(luas));
set(handles.edit2,'String',num2str(P));
set(handles.edit3,'String',num2str(L));
set(handles.edit4,'String',num2str(rasio));



% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;



function edit2_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 edit2_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



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



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



function edit7_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 edit7_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

Bagikan :
+
Previous
Next Post »
0 Komentar untuk "Menghitung Region Property Suatu Citra Yang di Akuisisi Dari Webcam"

 
Copyright © 2015 CATATULANG - All Rights Reserved
Template By Kunci Dunia
Back To Top