【虹膜识别】基于matlab GUI形态学虹膜检测【含Matlab源码 959期】
作者:互联网
一、简介
数学形态学操作可以分为二值形态学和灰度形态学,灰度形态学由二值形态学扩展而来。数学形态学有2个基本的运算,即腐蚀和膨胀,而腐蚀和膨胀通过结合又形成了开运算和闭运算。
开运算就是先腐蚀再膨胀,闭运算就是先膨胀再腐蚀。
1 二值形态学
粗略的说,腐蚀可以使目标区域范围“变小”,其实质造成图像的边界收缩,可以用来消除小且无意义的目标物。式子表达为:
该式子表示用结构B腐蚀A,需要注意的是B中需要定义一个原点,【而B的移动的过程与卷积核移动的过程一致,同卷积核与图像有重叠之后再计算一样】当B的原点平移到图像A的像元(x,y)时,如果B在(x,y)处,完全被包含在图像A重叠的区域,(也就是B中为1的元素位置上对应的A图像值全部也为1)则将输出图像对应的像元(x,y)赋值为1,否则赋值为0。
我们看一个演示图。
B依顺序在A上移动(和卷积核在图像上移动一样,然后在B的覆盖域上进行形态学运算),当其覆盖A的区域为[1,1;1,1]或者[1,0;1,1]时,(也就是B中‘1’是覆盖区域的子集)对应输出图像的位置才会为1。
2 膨胀
粗略地说,膨胀会使目标区域范围“变大”,将于目标区域接触的背景点合并到该目标物中,使目标边界向外部扩张。作用就是可以用来填补目标区域中某些空洞以及消除包含在目标区域中的小颗粒噪声。
该式子表示用结构B膨胀A,将结构元素B的原点平移到图像像元(x,y)位置。如果B在图像像元(x,y)处与A的交集不为空(也就是B中为1的元素位置上对应A的图像值至少有一个为1),则输出图像对应的像元(x,y)赋值为1,否则赋值为0。
演示图为:
3 小结
也就是说无论腐蚀还是膨胀,都是把结构元素B像卷积操作那样,在图像上平移,结构元素B中的原点就相当于卷积核的核中心,结果也是存储在核中心对应位置的元素上。只不过腐蚀是B被完全包含在其所覆盖的区域,膨胀时B与其所覆盖的区域有交集即可。
4 灰度形态学
在讲述灰度值形态学之前,我们进行一个约定,即将结构元素B覆盖住的图像A的区域记为P(取Part之意)。
5 灰度形态学的腐蚀
那么灰度形态学中的腐蚀就是类似卷积的一种操作,用P减去结构元素B形成的小矩形,取其中最小值赋到对应原点的位置即可。
我们来看一个实例,进行加深对灰度形态学的理解。
假设我们有如下的图像A和结构元素B:
进行灰度形态学腐蚀的过程如下:
我们对输出图像的第一个元素的输出结果进行具体的展示,也就是原点对应的4的位置。输出图像其他的元素的值也都是这样得到的。我们会看到,B首先覆盖的区域就是被减数矩阵,然后在其差矩阵中求min(最小值)来作为原点对应位置的值。
灰度形态学的膨胀
根据上面对腐蚀的描述,我们对膨胀做出同样的描述,灰度形态学中的膨胀就是类似卷积的一种操作,用P加上B,然后取这个区域中的最大值赋值给结构元素B的原点所对应的位置。
这里也对输出图像第一个元素值的来历做个说明。
对上面矩阵的和求最大值就是6,所以把6赋值给结构元素原点所对应的位置。
6 小结
上面介绍了灰度形态学的概念,这里来说一说各自的用处。相比较于原图像,因为腐蚀的结果要使得各像元比之前变得更小,所以适用于去除高峰噪声。而灰度值膨胀的结果会使得各像元比之前的变得更大,所以适用于去除低谷噪声。
二、源代码
function varargout = code(varargin)
% CODE M-file for code.fig
% CODE, by itself, creates a new CODE or raises the existing
% singleton*.
%
% H = CODE returns the handle to a new CODE or the handle to
% the existing singleton*.
%
% CODE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CODE.M with the given input arguments.
%
% CODE('Property','Value',...) creates a new CODE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before code_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to code_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 code
% Last Modified by GUIDE v2.5 07-May-2020 17:46:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @code_OpeningFcn, ...
'gui_OutputFcn', @code_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 code is made visible.
function code_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 code (see VARARGIN)
% Choose default command line output for code
handles.output = hObject;
clc;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes code wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = code_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 str
global filenamestr
global I2;
[filename,pathname]=uigetfile({'*.bmp';'*.jpg';'*.gif'},'选择图片');
if isequal(filename,0)
disp('Users Selected Canceled');
else
str=[pathname,filename];
filenamestr=filename;
im = imread(str);
I2 = imread(str);
axes(handles.axes1);%axes1是坐标轴的标示
imshow(im);
end
% --- 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 str
global template
global mask
global filenamestr
testimage=str;
hmthresh = 0.3;
write = 0;
nname=filenamestr(1:4);
samep=1; %判断是不是要与当前同一个人对比
if samep
InputPath=['.\',nname,'\']; %同一个人
else
InputPath='.\0024\'; %不同人
end
if exist(InputPath)
% [result,time] = final1(str)
templatetest=template;
masktest=mask;
tic
shibie();
axes(handles.axes12);
pic=[InputPath,result];
imshow(pic);title('匹配到虹膜');
else
result='o~o, No match found!';
end
set(handles.text2,'String',result);
t=toc;
disp(['识别用时:',num2str(t)])
% --- 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)
global str
global I2;
%I2=imread('image004.jpg');
% axes(handles.axes2);
% imshow(I2);
eI=edge(I2,'canny', 0.2);
axes(handles.axes3);
imshow(eI);title('canny边缘提取');
% 利用hough变换找到图像中的一个圆
[y0detect,x0detect,Accumulator] = houghcircle(eI,45,4);
axes(handles.axes4);
imshow(I2);
hold on;
for i=1:length(y0detect)
plot(x0detect,y0detect,'.r');hold on;
end
% figure;imshow(I2)
axes(handles.axes13);
imshow(Accumulator,[]);
[r,c]=size(I2);
M = circle( c,r,x0detect,y0detect,45);
axes(handles.axes5);
imshow(M,[]);
outI=M.*double(I2);
axes(handles.axes6);
imshow(outI,[]);
outI2=(1-M).*double(I2);
axes(handles.axes7);
imshow(outI2,[]);
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
% --- 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)
global str
global DIAGPATH % path for writing diagnostic images
%DIAGPATH = 'C:\Documents and Settings\Administrator\桌面\iris';
% DIAGPATH = 'D:\虹膜识别\算法\iris-张冲\template';
DIAGPATH = '.\0023\template';
eyeimage_filename=str;
write=0;
dingwei();
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles) %归一化
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global str
global polar_array
global noise_array
eyeimage_filename=str;
%参数设置
%normalisation parameters
radial_res = 100;
angular_res = 240;
write=0;
% with these settings a 9600 bit iris template is created
guiyihua();
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)%特征提取
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%feature encoding parameters
global str
global polar_array
global noise_array
global template
global mask
eyeimage_filename=str;
nscales=1;
minWaveLength=18;
mult=1; % not applicable if using nscales = 1
sigmaOnf=0.5;
tezhengtiqu()
% --- Executes during object creation, after setting all properties.
function axes10_CreateFcn(hObject, eventdata, handles) %归一化
% hObject handle to axes10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes10
% --- Executes on button press in pushbutton8.
% hObject handle to pushbutton8 (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 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)
clc;
close all;
% --- Executes during object creation, after setting all properties.
function axes4_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes4
三、运行结果
四、备注
版本:2014a
完整代码或代写加1564658423
标签:959,code,see,global,handles,hObject,源码,虹膜,eventdata 来源: https://www.cnblogs.com/homeofmatlab/p/14905985.html