一、形态学检测简介

1 图像分析及预处理
拍摄图像会产生随机的扰动,图像有一定的噪声,为消除掉图像中的无关信息,对图像进行预处理。

1.1 灰度化
为降低运算量,需要将拍摄的三通道的RGB图像转化为单通道的灰度图像。采用加权平均法的灰度化方法,其中心理学灰度公式根据人眼对RGB三色的敏感程度选择不同的权重:

式(1)中,R、G、B分别为RGB三通道灰度值,灰度化结果如图1 (a)所示。

1.2 平滑处理
为了尽可能避免将背景当作缺陷,需要对图像进行平滑处理,这样虽然会使缺陷的边界模糊,但是有利于减少背景的干扰。注意所采用的去噪处理为均值滤波,均值滤波公式为:

式(2)中,m、n分别为所选择的滤波核的长和宽,Sxy是以(x,y)为中心的滤波核对应像素的位置集合,平滑处理结果如图1 (b)所示。均值滤波的缺点是会使一些细节如边缘等信息丢失,因此在找到种子点后,对没有经过平滑处理的图像进行区域生长,找到缺陷边界。

2 算法原理
2.1 阈值分割

阈值分割是图像分割中最简单、基础的方法,性能比较稳定,计算量较小,运算速度快;它主要有全局阈值分割、局部阈值分割、自适应阈值分割等方法。阈值算法基于阈值T,将像素灰度值大于阈值T和小于阈值T的部分分别叫做前景和背景。变换函数表达式:

图1 均值滤波处理

式(3)中,T为阈值,g (x,y)为原图像像素点(x,y)的灰度值,f (x,y)为分割后图像像素点(x,y)的灰度值,阈值分割结果如图2所示。

图2 阈值分割结果

2.2 形态学开运算降噪
数学形态学简称形态学,其处理方式为领域运算,即把领域结构元素与图像对应位置像素进行逻辑运算,这种运算的影响因素主要有结构元素大小、形状和逻辑运算的规则。形态学操作主要有膨胀、腐蚀、梯度运算、礼帽运算、黑帽运算、开运算和闭运算等,但其基础为腐蚀和膨胀,利用膨胀和腐蚀就能完成不同形式的运算。

腐蚀运算能消除轮廓边界点,使边界向内缩小,主要用于细化二值图像目标轮廓、去除噪声等。

式(4)中,A为原图像,B为结构元素。首先给结构元素B定义一个原点,当结构元素B的原点移动到图像A的(x,y)上时,如果结构元素B上等于1的像素点对应图像A也等于1,则将图像A的(x,y)的灰度值置为1,否则置为0,腐蚀示意图如图3所示。

图3 腐蚀示意图
膨胀运算则与腐蚀运算相反,使边界向外扩张,主要用于填补图像分割后的空白,使相近的不相连的轮廓相连。其公式为:

式(5)中,A为原图像,B为结构元素。首先给结构元素B定义一个原点,当结构元素B的原点移动到图像A的(x,y)上时,如果结构元素B上等于1的像素点对应图像A中至少有一个等于1,则将图像A的(x,y)的灰度值置为1,否则置为0。

先进行腐蚀操作,然后在腐蚀的基础上进行膨胀操作,主要用于去噪和计数等。其公式为:

式(6)中,A为原图像,B、C为结构元素。开运算效果如图4所示,图5为开运算处理的结果。

图4 开运算效果
2.3 区域生长法
区域生长的思想就是把领域(四领域、八领域等)相同的化为一个区域。首先需要一个种子点作为生长的开始,然后将种子点领域内满足相似准则要求的像素点合并到种子的区域,将这个区域的像素做为种子点,继续进行生长,直到没有符合要求的点,生长结束,所有种子点像素作为生长的区域。分割的好坏由初始种子点和相似准则决定。

图5 形态学开运算结果
2.3.1 种子点选择与检测
经过阈值分割和形态学处理后,将二值图像各轮廓中心作为待定种子点。如果选择的种子点位于缺陷的绝对区域,那么种子点总有一个方向各像素的深度值呈现高-低-高的形态。设计检测模板如图6所示,计算出种子点在0°、45°、90°、135°方向上的深度变化,判断其变化是否呈高低高形态。

图6 检测模板
种子点左右两侧r个像素的灰度平均值分别为:

各方向的灰度变化为:

深度形Si态变化判定:

式(10)中,I (u)为检测模板中第u个像素的灰度值,w=1,2,3,4,分别代表0°,45°,90°,135°方向,mwm为w方向两侧的最小灰度值,T1为形态变化阈值。如果种子点不满足深度形态变化判定,则去除该待定种子点。

2.3.2 生长过程
区域生长的具体流程如下:
(1)将种子点坐标放入种子点集seeds。
(2)顶出种子点集中的一个种子点,对种子点八邻域的像素点进行相似准则判断;满足相似准则条件的点,视为种子点放入种子点集seeds。
(3)将顶出的种子点存入种子集S。
(4)如果种子点集内没有元素,则跳到步骤(4);如果种子点集中还有元素,则跳到步骤(2)。
(5)生成一张和输入图像长宽一致,像素值全为0的图像I。
(6)将图像I中对应种子集S坐标的像素值置为255,得到分割图像I’。
其中生长的相似准则为:

式(11)中,gray (seed)为当轮种子点的灰度值,gray (8_n)为其八邻域各点的像素值,Thresh为设置的阈值。区域生长结果如图7所示。

图7 区域生长结果
3 实验过程
图像分割就是按照预先设定的规则,将图像分割为有意义的前景和背景的过程。区域生长是一个分割效果比较好的算法,但前提是需要找到适合的种子点。单一的分割算法就容易遇到这种不足的情况,结合使用形态学和阈值分割的方法来找到合适的种子点,帮助区域生长算法完成分割任务,达到满足要求的分割效果,分割方法流程如图8所示。

图8 分割流程图
首先对输入的图片进行灰度化处理,变成单通道的灰度图片,然后滤波去除噪声,使图像更平滑,选择合适的阈值进行阈值分割,在利用开运算去除掉分割后较小的前景,以各前景区域的中心点为起始种子点,进行区域生长,得到最终所满足要求的前景。

二、部分源代码

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});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_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 samepInputPath=['.\',nname,'\']; %同一个人
elseInputPath='.\0024\'; %不同人
end
if exist(InputPath)
% [result,time] = final1(str)
templatetest=template;
masktest=mask;
tic
shibie();
axes(handles.axes12);
pic=[InputPath,result];
imshow(pic);title('匹配到虹膜');
elseresult='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 = ' 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

三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.

【虹膜识别】基于matlab GUI形态学虹膜检测【含Matlab源码 959期】相关推荐

  1. 【光学】基于matlab GUI杨氏双缝干涉【含Matlab源码 001期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI杨氏双缝干涉[含Matlab源码 001期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付费 ...

  2. 基于Opencv的车距检测系统(源码&教程)

    1.研究背景 对本车前方车辆的识别及距离检测是计算机视觉技术在智能网联汽车中的一个重要内容.要想在错综繁杂的交通环境中实现无人驾驶,对行车环境中其他车辆信息的获取是十分重要的.因此,对本车前方车辆的识 ...

  3. 基于YOLOv7的芯片表面缺陷检测系统(源码&教程)

    1.项目背景: 目前随着电子领域的快速发展,芯片也已经成为日常生活中不可或缺的一部分.随着市场对芯片的需求不断增大,裸芯片表面缺陷检测任务的压力也越来越大.裸芯片表面的缺陷检测不仅能保证芯片成品的质量 ...

  4. Python基于OpenCV监控老鼠蟑螂检测系统[完整源码&部署教程]

    1.视频演示: [项目分享]Python基于OpenCV监控老鼠蟑螂检测系统[完整源码&部署教程]_哔哩哔哩_bilibili 2.图片演示: 3.明厨亮灶: 餐饮企业的厨房卫生状况一直饱受消 ...

  5. 基于OpenCV监控老鼠蟑螂检测系统[完整源码&部署教程]

    1.视频演示: [项目分享]Python基于OpenCV监控老鼠蟑螂检测系统[完整源码&部署教程]_哔哩哔哩_bilibili 2.图片演示: 3.算法原理: 该博客提出的移动侦测即是根据视频 ...

  6. Android实现红绿灯检测(含Android源码 可实时运行)

    Android实现红绿灯检测(含Android源码 可实时运行) 目录 Android实现红绿灯检测(含Android源码 可实时运行) 1. 前言 2. 红绿灯检测数据集说明 3. 基于YOLOv5 ...

  7. 【人脸识别】基于matlab GUI人数统计【含Matlab源码 2121期】

    ⛄一.人数统计简介(附课程作业报告) 1 课题背景 本课题为基于matlab的人数统计系统.近年来,很多行业对人流信息有极大的需求,如汽车公交站,地铁站台,商场出入口等.通过人数统计系统可以方便.可靠 ...

  8. 基于SSM的仓库管理系统(含完整源码+论文)

    后端框架:SSM 数据库:MySQL 开发工具:IDEA/Eclipse 系统介绍:本系统是基于SSM框架进行设计,MySQL作为底层数据库,前端采用bootstrap 模块大致介绍:包括库存管理.出 ...

  9. 【心电信号】基于matlab GUI心电信号预处理【含Matlab源码 938期】

    ⛄一.心电信号预处理方法简介 理论知识参考文献:心电信号预处理方法研究 ⛄二.部分源代码 function varargout = kaishi(varargin) gui_Singleton = 1 ...

  10. 【图像检测】基于计算机视觉实现米粒个数检测含Matlab源码

    1 简介 2 部分代码 function varargout = mygui(varargin)​​% Begin initialization code - DO NOT EDITgui_Singl ...

最新文章

  1. python实现登录网站下载文件-Python爬虫 登录网页后下载图片,怎么保持登录状态?...
  2. 不同配置决定不同的复制的流程
  3. 纽约时报:人们正成为移动通讯的奴隶
  4. SourceTree 免登录跳过初始设置
  5. TP5项目lnmp环境500错误
  6. openNLP--Sentence Detector
  7. 10+年程序员告诉你职场误区,如何快速提升自己?
  8. 分析arm Internal error: synchronous external abort: 96000010 [#1] PREEMPT SMP
  9. html原生listview,Html中使用M$控件系列之 ListView 篇
  10. 帝国cms免登陆生成html,帝国cms7.5免登陆发布模块
  11. Adapter模式 适配器模式
  12. 老杨说运维 | 证券行业运维数字化和智能化转型实践探索
  13. Python数据分析案例06——现代人的婚育意愿调查分析(基于逻辑回归模型和问卷数据)
  14. 用计算机弹大白菜鸡毛菜,抖音大白菜鸡毛菜是什么梗-抖音大白菜鸡毛菜梗意思介绍-仓鼠手游...
  15. 性能测试怎么监控服务器,性能测试篇 :Jmeter监控服务器性能
  16. 用户注册邮箱通知和短信通知详解(php)
  17. 计算机键盘上顿号在哪,顿号在键盘上怎么打?顿号怎么打出来?
  18. 2018华为软件精英挑战赛
  19. PHP一句话木马Webshell变形免杀总结
  20. 数据结构与算法(C++实现)

热门文章

  1. sklearn学习笔记之开始
  2. 图片垂直居中 和 float
  3. mysql open files
  4. PowerDesigner 15 概述
  5. Mojoportal 的用户系统
  6. 统计各班参加补考的人数
  7. php基本语法的几点备忘
  8. 传智播客 sklearn数据集与机器学习组成
  9. 每日一句20191019
  10. 181002有道扇贝每日一句