指纹识别算法

更新时间:2023-10-21 06:13:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

function fpextractdemo(action, varargin) %

FPEXTRACTDEMO 指纹特征提取演示程序

% Modified by PRTsinghua@hotmail.com %

% 输入图像必须是256×256的灰度图 % 8-bit灰度级的图像 @ 500 dpi.

% 如果这些条件不满足,一些函数中的参数必须做相应的改变 % % % 选项:

% - Centralize: 二值化图像,计算中心点 % - Crop: 图像修剪 % - Sectorize: 可视化扇形 % - Normalize: 归一化输入图像 % - Gabor filters: 可视化Gabor滤波器

% - Convolute: 计算输入图像和Gabor滤波器的convolution % - Features: 特征可视化

% - FingerCode: 在数据库中加入该指纹 % - Check: 指纹匹配 % %

% 指纹识别中一个至关重要的步骤就是中心点的确定。如果剪切指纹图像时出现了任何

% 错误,你可以使用辅助的m文件\:它使得输入指纹可视化并计算指纹

% 中心,借助于m函数 \。

%

% 在MATLAB的命令行提示中输入 \运行程序

%-------------------------------------------------------------------------- if nargin<1,

action='InitializeFPEXTRACTDEMO'; end;

feval(action,varargin{:}) return; %%%

%%% 子函数 - InitializeFPEXTRACTDEMO %%%

function InitializeFPEXTRACTDEMO()

% 如果 fpextractdemo 已经在运行,将之转到前台

h = findobj(allchild(0), 'tag', 'Extracting FingerPrint Features Demo ( Modified by PRTsinghua@hotmail.com v) '); if ~isempty(h) figure(h(1)) return end

screenD = get(0, 'ScreenDepth'); if screenD>8 grayres=256; else

grayres=128; end

FpextractDemoFig = figure( ...

'Name','指纹特征提取演示程序 Modified by PRTsinghua@hotmail.com', ... 'NumberTitle','off', 'HandleVisibility', 'on', ... 'tag', '指纹特征提取演示程序', ... 'Visible','off', 'Resize', 'off',...

'BusyAction','Queue','Interruptible','off', ... 'Color', [.8 .8 .8], ... 'IntegerHandle', 'off', ... 'Colormap', gray(grayres));

figpos = get(FpextractDemoFig, 'position'); figpos(3:4) = [1024 525];

% Adjust the size of the figure window horizDecorations = 10; % 调整大小. vertDecorations = 45; % 标题栏. screenSize = get(0,'ScreenSize');

dx = screenSize(3) - figpos(1) - figpos(3) - horizDecorations; dy = screenSize(4) - figpos(2) - figpos(4) - vertDecorations; if (dx < 0)

figpos(1) = max(5,figpos(1) + dx); end if (dy < 0)

figpos(2) = max(5,figpos(2) + dy); end

set(FpextractDemoFig, 'position', figpos);

rows = figpos(4); cols = figpos(3); % Colors

bgcolor = [0.45 0.45 0.45]; % 背景颜色 wdcolor = [.8 .8 .8]; fgcolor = [1 1 1];

hs = (cols-(6*175)) / 5; vs = (rows)/8;

%==================================== % 所有菜单和按钮的参数

Std.Interruptible = 'off'; Std.BusyAction = 'queue';

% Defaults for image axes Ax = Std; Ax.Units = 'Pixels';

Ax.Parent = FpextractDemoFig; Ax.ydir = 'reverse'; Ax.XLim = [.5 128.5]; Ax.YLim = [.5 128.5]; Ax.CLim = [0 1]; Ax.XTick = [];

% 水平间隔

% 垂直间隔

% Window 颜色

% 文本

Ax.YTick = [];

Img = Std; Img.CData = []; Img.Xdata = [1 128]; Img.Ydata = [1 128]; Img.CDataMapping = 'Scaled'; Img.Erasemode = 'none';

Ctl = Std; Ctl.Units = 'Pixels';

Ctl.Parent = FpextractDemoFig;

Btn = Ctl;

Btn.Style = 'pushbutton'; Btn.Enable = 'off';

Edit = Ctl; Edit.Style = 'edit';

Edit.HorizontalAlignment = 'right'; Edit.BackgroundColor = 'white'; Edit.ForegroundColor = 'black';

Menu = Ctl;

Menu.Style = 'Popupmenu';

Text = Ctl; Text.Style = 'text';

Text.HorizontalAlignment = 'left'; Text.BackgroundColor = bgcolor;

LoadNewImage(FpextractDemoFig); SelectExtractingStep(FpextractDemoFig); return

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%

%%% 子函数 - LoadNewImage %%%

function LoadNewImage(DemoFig) % 加载新图像

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch'); ud=get(DemoFig,'Userdata');

v = get(ud.hImgPop,{'value','String'}); name = deblank(v{2}(v{1},:)); drawnow

switch name case 'Right loop', namefile='37_7.bmp'; [img,map]=imread(namefile); case 'Whorl',

namefile='19_7.bmp'; [img,map]=imread(namefile); case 'Left loop',

namefile='37_3.bmp'; [img,map]=imread(namefile); case 'Twin loop',

namefile='37_5_2.bmp'; [img,map]=imread(namefile); case 'Other image',

[namefile,pathname]=uigetfile('*.bmp','请选择一个256×256的灰度位图'); if namefile~=0

[img,map]=imread(strcat(pathname,namefile)); else

disp(' Chose a file! '); [img,map]=imread('37_7.bmp'); end otherwise

error('fpextractdemo: Unknown Image Option!'); end

% 如果图像大小 N x M 且 mod(N,8)~=0 或者 mod(M,8)~=0 % 则改变图像大小 imgN=size(img,1); imgM=size(img,2); modN=mod(imgN,8); modM=mod(imgM,8);

%---------------------------------------- % 将信息保存在 informations.dat if isa(img,'uint8')

graylevmax=2^8-1; end

if isa(img,'uint16') graylevmax=2^16-1; end

if isa(img,'uint32') graylevmax=2^32-1; end

save('informations.dat','graylevmax','img'); %----------------------------------------- % 改变图像大小

%----------------------------------------- img=img(modN+1:imgN,modM+1:imgM); %----------------------------------------- img = double(img)/graylevmax;

set(get(ud.hOriginalAxes, 'title'), 'string', '原始指纹图像'); set(get(ud.hComponent1Axes, 'title'), 'string', '0 度组成'); set(get(ud.hComponent6Axes, 'title'), 'string', '112.5 度组成'); set(ud.hOriginalImage, 'Cdata', img); set(DemoFig,'Pointer','arrow');

setstatus(DemoFig,'Please select a step to process...'); return;

%======================================== %%%

%%% 子函数 - SelectExtractingStep %%%

function SelectExtractingStep(DemoFig)

% Load a step

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch'); ud=get(DemoFig,'Userdata');

v = get(ud.hSelectStepPop,{'value','String'}); name = deblank(v{2}(v{1},:)); drawnow

switch name case 'Centralize', Centralize(DemoFig); case 'Crop', Crop(DemoFig); case 'Sectorize', Sectorize(DemoFig); case 'Normalize', Normalize(DemoFig); case 'Gabor filters', Gaborfilter(DemoFig); case 'Convolute', Convolute(DemoFig); case 'Features', Features(DemoFig); case 'FingerCode', Fingercode(DemoFig); case 'Check',

Check(DemoFig); otherwise

error('fpextractdemo: Unknown Image Option!'); end return;

%========================================================================== %%%

%%% 子函数 - Centralize %%%

function Centralize(DemoFig)

load 'informations.dat' -mat

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch');

setstatus(DemoFig,'正在计算中心,请等待......'); ud=get(DemoFig,'Userdata');

fingerprint = getimage(ud.hOriginalImage); fingerprint = fingerprint*graylevmax;

[BinarizedPrint,XofCenter,YofCenter] = centralizing(fingerprint,0);

set(get(ud.hComponent8Axes, 'title'), 'string', '二值化图像'); set(ud.hComponent8Image, 'Cdata', BinarizedPrint);

set(get(ud.hComponent4Axes, 'title'), 'string', '67.5 度 gabor'); set(ud.hComponent4Image, 'Cdata', gabor); case (angle==4),

set(get(ud.hComponent5Axes, 'title'), 'string', '90 度 gabor'); set(ud.hComponent5Image, 'Cdata', gabor); case (angle==5),

set(get(ud.hComponent6Axes, 'title'), 'string', '112.5 度 gabor'); set(ud.hComponent6Image, 'Cdata', gabor); case (angle==6),

set(get(ud.hComponent7Axes, 'title'), 'string', '135 度 gabor'); set(ud.hComponent7Image, 'Cdata', gabor); case (angle==7),

set(get(ud.hComponent8Axes, 'title'), 'string', '157.5 度 gabor'); set(ud.hComponent8Image, 'Cdata', gabor); otherwise

error('Nothing !'); end end

set(DemoFig,'Pointer','arrow');

setstatus(DemoFig,'Gabor Filters were shown'); ud.OriginalImageIsStale = 0; set(DemoFig, 'UserData', ud); drawnow

%========================================================================== %%%

%%% 子函数 - Convolute %%%

function Convolute(DemoFig) %

load 'informations.dat' -mat

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch');

setstatus(DemoFig,'正在处理8个Gabor滤波器,旋转......'); ud=get(DemoFig,'Userdata');

fingerprint = getimage(ud.hOriginalImage);

load 'informations.dat' -mat

fingerprint = fingerprint*graylevmax; N=175; num_disk=8;

[BinarizedPrint,XofCenter,YofCenter]=centralizing(fingerprint,0); [CroppedPrint]=cropping(XofCenter,YofCenter,fingerprint); [NormalizedPrint,vector]=sector_norm(CroppedPrint,0,1); for (angle=0:1:num_disk-1)

gabor=gabor2d_sub(angle,num_disk); z2=gabor;

z1=NormalizedPrint;

z1x=size(z1,1); z1y=size(z1,2); z2x=size(z2,1); z2y=size(z2,2);

ComponentPrint=real(ifft2(fft2(z1,z1x+z2x-1,z1y+z2y-1).*fft2(z2,z1x+z2x-1,z1y+z2y-1)));

px=((z2x-1)+mod((z2x-1),2))/2; py=((z2y-1)+mod((z2y-1),2))/2;

ComponentPrint=ComponentPrint(px+1:px+z1x,py+1:py+z1y);

[disk,vector]=sector_norm(ComponentPrint,1,0); img = double(ComponentPrint)/graylevmax;

switch angle<8 case (angle==0),

set(get(ud.hComponent1Axes, 'title'), 'string', '0 度组成'); set(ud.hComponent1Image, 'Cdata', img); case (angle==1),

set(get(ud.hComponent2Axes, 'title'), 'string', '22.5 度组成'); set(ud.hComponent2Image, 'Cdata', img); case (angle==2),

set(get(ud.hComponent3Axes, 'title'), 'string', '45 度组成'); set(ud.hComponent3Image, 'Cdata', img); case (angle==3),

set(get(ud.hComponent4Axes, 'title'), 'string', '67.5 度组成'); set(ud.hComponent4Image, 'Cdata', img); case (angle==4),

set(get(ud.hComponent5Axes, 'title'), 'string', '90 度组成');

set(ud.hComponent5Image, 'Cdata', img); case (angle==5),

set(get(ud.hComponent6Axes, 'title'), 'string', '112.5 度组成'); set(ud.hComponent6Image, 'Cdata', img); case (angle==6),

set(get(ud.hComponent7Axes, 'title'), 'string', '135 度组成'); set(ud.hComponent7Image, 'Cdata', img); case (angle==7),

set(get(ud.hComponent8Axes, 'title'), 'string', '157.5 度组成'); set(ud.hComponent8Image, 'Cdata', img); otherwise

error('Nothing !'); end end

set(DemoFig,'Pointer','arrow'); setstatus(DemoFig,'旋转结束'); set(DemoFig, 'UserData', ud); drawnow

%========================================================================== %%%

%%% 子函数 - Features %%%

function Features(DemoFig) %

load 'informations.dat' -mat

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch');

setstatus(DemoFig,'正在处理8个Gabor滤波器,旋转......'); ud=get(DemoFig,'Userdata');

fingerprint = getimage(ud.hOriginalImage);

fingerprint = fingerprint*graylevmax; N=175; num_disk=8;

[BinarizedPrint,XofCenter,YofCenter]=centralizing(fingerprint,0); [CroppedPrint]=cropping(XofCenter,YofCenter,fingerprint); [NormalizedPrint,vector]=sector_norm(CroppedPrint,0,1);

for (angle=0:1:num_disk-1)

gabor=gabor2d_sub(angle,num_disk); z2=gabor;

z1=NormalizedPrint; z1x=size(z1,1); z1y=size(z1,2); z2x=size(z2,1); z2y=size(z2,2);

ComponentPrint=real(ifft2(fft2(z1,z1x+z2x-1,z1y+z2y-1).*fft2(z2,z1x+z2x-1,z1y+z2y-1)));

%========================================================================== %%%

%%% 子函数 - Check %%%

function Check(DemoFig) %

load 'informations.dat' -mat

if nargin<1 DemoFig = gcbf; end

set(DemoFig,'Pointer','watch');

setstatus(DemoFig,'正在搜索数据库......'); ud=get(DemoFig,'Userdata');

fingerprint = getimage(ud.hOriginalImage);

fingerprint = fingerprint*graylevmax; N=175; num_disk=8;

[BinarizedPrint,XofCenter,YofCenter]=centralizing(fingerprint,0); [CroppedPrint]=cropping(XofCenter,YofCenter,fingerprint); [NormalizedPrint,vector]=sector_norm(CroppedPrint,0,1);

for (angle=0:1:num_disk-1)

gabor=gabor2d_sub(angle,num_disk); z2=gabor;

z1=NormalizedPrint; z1x=size(z1,1); z1y=size(z1,2); z2x=size(z2,1); z2y=size(z2,2);

ComponentPrint=real(ifft2(fft2(z1,z1x+z2x-1,z1y+z2y-1).*fft2(z2,z1x+z2x-1,z1y+z2y-1)));

px=((z2x-1)+mod((z2x-1),2))/2; py=((z2y-1)+mod((z2y-1),2))/2;

ComponentPrint=ComponentPrint(px+1:px+z1x,py+1:py+z1y); [disk,vector]=sector_norm(ComponentPrint,1,0); %img = double(ComponentPrint)/graylevmax; %img1 = double(disk)/51200; finger_code{angle+1}=vector(1:36); end

% 输入指纹的编码已经计算,检查数据库 if (exist('fp_database.dat')==2) load('fp_database.dat','-mat');

%---- 申请内存 ----------------------------------- ruoto1=zeros(36,1); ruoto2=zeros(36,1); vettore_d1=zeros(12,1); vettore_d2=zeros(12,1);

best_matching=zeros(fp_number,1);

% 开始检查 --------------------------------------- for scanning=1:fp_number fcode1=data{scanning,1}; fcode2=data{scanning,2}; for rotazione=0:1:11 d1=0; d2=0; for disco=1:8 f1=fcode1{disco}; f2=fcode2{disco};

% ora ruoto f1 ed f2 della rotazione ciclica ---------- for old_pos=1:12

new_pos=mod(old_pos+rotazione,12); if (new_pos==0) new_pos=12; end

ruoto1(new_pos)=f1(old_pos); ruoto1(new_pos+12)=f1(old_pos+12); ruoto1(new_pos+24)=f1(old_pos+24); ruoto2(new_pos)=f2(old_pos); ruoto2(new_pos+12)=f2(old_pos+12); ruoto2(new_pos+24)=f2(old_pos+24); end

%------------------------------------------------------- d1=d1+norm(finger_code{disco}-ruoto1);

d2=d2+norm(finger_code{disco}-ruoto2); end

vettore_d1(rotazione+1)=d1; vettore_d2(rotazione+1)=d2; end

[min_d1,pos_min_d1]=min(vettore_d1); [min_d2,pos_min_d2]=min(vettore_d2); if min_d1

minimo=min_d2; end

best_matching(scanning)=minimo; end

[distanza_minima,posizione_minimo]=min(best_matching); beep;

message=strcat('数据库中与输入指纹最匹配的是:',num2str(posizione_minimo),... ' 其距离为: ',num2str(distanza_minima)); msgbox(message,'数据库信息','帮助');

%------------------------------------------------------- else

message='数据库为空,无法检查';

msgbox(message,'指纹编码数据库错误','警告'); end

set(DemoFig,'Pointer','arrow'); setstatus(DemoFig,'数据库搜索完毕'); set(DemoFig, 'UserData', ud); drawnow

%==========================================================================

指纹文件夹

本文来源:https://www.bwwdw.com/article/e1pf.html

Top