function varargout = untitled1111(varargin)
% UNTITLED1111 M-file for untitled1111.fig
% UNTITLED1111, by itself, creates a new UNTITLED1111 or raises the existing
% singleton*.
%
% H = UNTITLED1111 returns the handle to a new UNTITLED1111 or the handle to
% the existing singleton*.
%
% UNTITLED1111('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED1111.M with the given input arguments.
%
% UNTITLED1111('Property','Value',...) creates a new UNTITLED1111 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled1111_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled1111_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 untitled1111
% Last Modified by GUIDE v2.5 12-Jun-2010 15:25:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1111_OpeningFcn, ...
'gui_OutputFcn', @untitled1111_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 untitled1111 is made visible.
function untitled1111_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 untitled1111 (see VARARGIN)
% Choose default command line output for untitled1111
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled1111 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled1111_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)
% 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)
global im;
[filename,pathname]= uigetfile( ...
{'*.bmp;*.jpg;*.gif;*.tif','Image Files (*.bmp,*.jpg,*.gif,*.tif)';
'*.bmp', 'BMP-files (*.bmp)'; ...
'*.jpg','JPG-files (*.jpg)'; ...
'*.gif','GIF-files (*.gif)'; ...
'*.tif','TIF-files (*.tif)'; ...
'*.*', 'All Files (*.*)'}, ...
'');
str=[pathname filename];
im=imread(str);
imshow(im);
% --- 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)
global im;
global q;
if length(size(im))==3
q=rgb2gray(im);
else q=im;
end
q1=imread('pic.bmp'); %眼睛模板
[px1,py1]=size(q1);
popsize=100; %设置初始参数,群体大小
chromlength=16; %字符串长度(个体长度),染色体长度
pc=0.6; %设置交叉概率
pm=0.1; %设置变异概率
pop=initpop(popsize,chromlength); %运行初始化函数,随机产生初始群体
dai=200; %20为迭代次数
for i=1:dai
[objvalue]=calobjvalue(pop,q); %计算目标函数
fitvalue=calfitvalue(objvalue); %计算群体中每个个体的适应度
[newpop]=selection(pop,fitvalue); %复制
[newpop]=crossover(newpop,pc); %交叉
[newpop]=mutation(newpop,pm); %变异
[bestindividual,bestfit]=best(pop,fitvalue);%求出群体中适应值最大的个体及其适应值
c(i)=max(bestfit);
pop5=bestindividual;
x1(i)=decodechrom(pop5,1,8);
y1(i)=decodechrom(pop5,9,8);
pop=newpop;
end
z=[c
x1
y1];
x=z(2,1);
y=z(3,1);
r=z(1,1);
for i=2:dai
if z(1,i)>r
x=z(2,i);
y=z(3,i);
r=z(1,i);
end
end
bx=[x x+py1-1 x+py1-1 x];
by=[y y y+3*px1-1 y+3*px1-1];
BW=roipoly(q,bx,by);
bx1=[x-1 x+py1 x+py1 x-1];
by1=[y-1 y-1 y+3*px1 y+3*px1];
BW1=roipoly(q,bx1,by1);
BW2=BW1-BW;
q3=double(q)/255;
Q=q3+BW2;
figure,imshow(Q)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf);
% --- Executes during object creation, after setting all properties.
function uipanel2_CreateFcn(hObject, eventdata, handles)
% hObject handle to uipanel2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --------------------------------------------------------------------
function uipanel2_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to uipanel2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
str=get(hObject,'string');
axes(handles.axes1);
switch str
case '原始图像' %原始图像
imshow(im);
case 'sobel' %sobel算子
if length(size(im))==3
q=rgb2gray(im);
end
BW1=edge(q,'sobel');
figure,imshow(BW1);
case 'prewitt' %prewitt算子
if length(size(im))==3
q=rgb2gray(im);
end
BW2=edge(q,'prewitt');
figure,imshow(BW2);
case 'canny' %canny算子
if length(size(im))==3
q=rgb2gray(im);
end
BW3=edge(q,'canny');
figure,imshow(BW3);
case '直方图' %直方图
if length(size(im))==3
q=rgb2gray(im);
end
figure,imhist(q);
end;
% --- Executes on button press in radiobutton7.
function radiobutton7_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton7
% --- 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)