function varargout = grafika(varargin)
% GRAFIKA M-file for grafika.fig
% GRAFIKA, by itself, creates a new GRAFIKA or raises the existing
% singleton*.
%
% H = GRAFIKA returns the handle to a new GRAFIKA or the handle to
% the existing singleton*.
%
% GRAFIKA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GRAFIKA.M with the given input arguments.
%
% GRAFIKA('Property','Value',...) creates a new GRAFIKA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before grafika_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to grafika_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help grafika
% Last Modified by GUIDE v2.5 27-Nov-2007 14:56:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @grafika_OpeningFcn, ...
'gui_OutputFcn', @grafika_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 grafika is made visible.
function grafika_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 grafika (see VARARGIN)
% Choose default command line output for grafika
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes grafika wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = grafika_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 squares_Callback(hObject, eventdata, handles)
% hObject handle to squares (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 squares as text
% str2double(get(hObject,'String')) returns contents of squares as a double
% --- Executes during object creation, after setting all properties.
function squares_CreateFcn(hObject, eventdata, handles)
% hObject handle to squares (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% hObject handle to calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
format long
%podzial na zbior do nauki i testowania w proporcji 2/3 do 1/3
set_size = 27
%zbior do nauki = 2/3 calosci, ceil zaokragla wynik w gore
learning_set = ceil( set_size * (2/3))
%zbior do testowania
testing_set = set_size - learning_set
%rozmiar alfabetu
alphabet_size=45;
%liczba kwadratow dzielacych wzorzec w pionie i poziomie
number_of_squares = str2num( get( handles.squares , 'string' ) );
number_of_squares;
%zmienne pomocnicze przy tworzeniu scieki dostpu do wzorc體
path_part_1=11;
path_part_2=0;
%znacznik poczatku odliczania czasu dzialania algorytmu
tic
%---------------------------- uczenie ---------------------------------
for k=1:alphabet_size
path_part_1;
path_part_2;
if (path_part_2 > 7)
path_part_2 = 0;
path_part_1 = path_part_1 + 1;
end
%macierz losowego podziau pr骲ek na zestaw uczcy i testujcy
DIVISION(k,:) = zeros(1,set_size);
t = 1;
signal = 0;
while 1
tmp = floor(100*rand);
if ((tmp > 0) & (tmp <= set_size))
signal = 1;
for i = 1:set_size
if (DIVISION(k,i) == tmp)
signal = 0;
break;
end
end
end
if (signal == 1)
DIVISION(k,t)=tmp;
t=t+1;
end
if (t>set_size)
break;
end
signal = 0;
end
TMP_BLACKEN = zeros(learning_set,16);
for l = 1:learning_set
if (DIVISION(k,l) < 10)
path = ['hand_probki\0' int2str(path_part_1) '_0' int2str(path_part_2) '\0' int2str(DIVISION(k,l)) '.tif'];
else
path = ['hand_probki\0' int2str(path_part_1) '_0' int2str(path_part_2) '\' int2str(DIVISION(k,l)) '.tif'];
end
%wczytanie obrazka, 1 - piksele biae, 0 - piksele czarne
I=imread(path);
div = (size(I)/number_of_squares);
%reszta z dzielenia rozmiaru macierzy I przez ilosc podzial體
remainder = rem(size(I),number_of_squares);
div = int16(floor(div));
t_hor = int16(1);
t_ver = int16(1);
n=1;
for i = 1:number_of_squares
for j = 1:number_of_squares
if (j~=number_of_squares & i~=number_of_squares)
SQUARE = I(t_ver:i*div(1),t_hor:j*div(2));
%TMP_BLACKEN - stosunek zaczernienia kwadratu do
%calosci obrazu
TMP_BLACKEN(l,n) = (sum((sum(SQUARE))')) / (sum((sum(I))'));
n=n+1;
size(SQUARE);
elseif ( i==number_of_squares & j~=number_of_squares )
SQUARE = I(t_ver:i*div(1)+remainder(1),t_hor:j*div(2));
TMP_BLACKEN(l,n) = (sum((sum(SQUARE))')) / (sum((sum(I))'));
n=n+1;
size(SQUARE);
elseif ( j==number_of_squares & i~=number_of_squares )
SQUARE = I(t_ver:i*div(1),t_hor:j*div(2)+remainder(2));
TMP_BLACKEN(l,n) = (sum((sum(SQUARE))')) / (sum((sum(I))'));
n=n+1;
size(SQUARE);
else
SQUARE = I(t_ver:i*div(1)+remainder(1),t_hor:j*div(2)+remainder(2));