
                           


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

% Last Modified by GUIDE v2.5 27-Jan-2010 22:06:25

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

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

% Update handles structure
guidata(hObject, handles);

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


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

L=uigetfile('*.jpg');            
[N M s]=size(L);
%L=double(L)./255;
figure, imshow(L);
title('Исходное изображение');
set(text1,'string','')

% 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)


% --- Executes on key press with focus on pushbutton1 and none of its controls.

function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)

% eventdata  structure with the following fields (see UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.

function pushbutton1_ButtonDownFcn(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)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
%Выбор пикселей лица с характерным цветом
[x,y,z]=impixel;
r=median(z(:,1)); std_r=std(z(:,1)); 
g=median(z(:,2)); std_g=std(z(:,2)); 
b=median(z(:,3)); std_b=std(z(:,3)); 
 
%Сегментация на основе анализа цвета
for i=1:N;
 %disp(i);
 for j=1:M;
  if  (abs(L(i,j,1)-r)<std_r)&(abs(L(i,j,2)-g)<std_g)&(abs(L(i,j,3)-b)<std_b);
    L1(i,j)=1;
   else
     L1(i,j)=0;
   end;
end;
end;
figure, imshow(L1);title('Исходное изображение после сегментации');



% 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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
%Удаление объектов, площадь которых меньше некоторой  заданной величины (для удаления шума)
HF2=figure;
[mitka num]=bwlabel(L1,8);
feats=imfeature(mitka,'Area',8);
Areas=zeros(num);
for i=1:num;
    Areas(i)=feats(i).Area;
end;
idx=find(Areas>750);
L1=ismember(mitka,idx);
figure(HF2),imshow(L1);title('После удаления шума (небольших объектов)');


% 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 pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton4 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
metric=4*pi*area/perimeter^2.
stats=regionprops(L1, 'Area', 'Centroid');
threshold=0.94;
c=0;
% окружность границ
for k=1:length(B)
  % получение координат границ (X, Y), соответствующих метке 'k'
  boundary=B{k};
  % вычисление измерений на основе периметра объектов
  delta_sq=diff(boundary).^2;    
  perimeter=sum(sqrt(sum(delta_sq, 2)));
  % получение вычисленной площади, соответствующей метке 'k'
  %area=stats(k).Area;  % Отключил, т.к. не запускается программа
  % вычисление характеристики округлости metric
  metric=4*pi*area/perimeter^2;
  if (metric > 0.65) & (metric<0.85)
    c=c+1;
    end
  % отображение результатов
  metric_string=sprintf('%2.2f', metric);
  % маркирование объектов
  if metric>threshold
    centroid=stats(k).Centroid;
    plot(centroid(1), centroid(2), 'ko');
  end
  
 % text(boundary(1, 2)-35, boundary(1, 1)+13, metric_string,'Color', 'y', 'FontSize', 14, 'FontWeight', 'bold');
end
%title(['Metrics closer to 1 indicate that the object is approximately round']);
% Вывод заключения в диалоговом окне: При нулевой найденной округлости -
% ответ отрицательный на наличие ли
if (c>0)
    msgbox('Возможно изображение человека','Заключение','OKonly')
else
    msgbox('Наличие изображения человека под сомнением','Заключение','OKonly')
end






