@新手求助@手指静脉识别代码 matlab 代码输入不正确求牛人解答!!!!

weixin_42264855 2018-05-21 11:41:48
function main()

huidujuzheng1=zeros(90,90);
huidujuzheng2=zeros(90,90);
m=0;
for i=1:8
for j=1:10
m=m+1;
n=0;
for l=i+1:9
for h=1:10
n=n+1;
huidujuzheng1(m,n)=tongji(i,j,l,h);
end
end
end
end
[count1,xl]=imhist(huidujuzheng1);
count1(1)=0;
count1=countl/250;

k=0;

for i=1:9
for j=1:9
k=k+1;
l=0;
for h=j+1:10
l=l+1;



huidujuzheng2(k,l)=tongji(i,j,i,h);
end
end
end
[count2,x2]=imhist(huidujuzheng1);
count2(1)=0;
count2=count2/250;
figure,plot(x1,count1,':',x2,count2)
save('D:\Program Files\MATLAB\R2011a\ceshi\data3.mat','count1','x1','count2','x2');

function [ceshi,m,n]=leichuli(strh,nn)

str=strcat('D:\Program Files\MATLAB\R2011a\ceshi\',int2str(strh),'\',int2str(nn),'.bmp');
k=imread(str);
k=guiyihua(k);
cheshi=zeros(m,n);
cesh=zeros(m,n);
shuchu=jibofenge(k);
k=tianchong(shuchu,20);
k=medfilt2(k);
k=lvbo(k,200);
k=bwmorph(k,'thin',Inf);
ceshi=chj(k,8,50);
ceshi(:,:)=cesh(:,:);
function[minn,maxx]=bianjie(h1)

m=[];
[g,num]=bwlabel(h1,8);
for i=1:num
[r,c]=find(bwlabel(h1)==i);
m(i)=max(c);
m(i+1)=min(c);
end
if m(1)>m(3)
minn=m(2);
maxx=m(4);
elseminn=m(1);
maxx=m(3);
end

function[minn,maxx]=caijian(shurutuxiang,caijianshu)
[m,n]=size(shurutuxiang);
%shurutuxiang=shurutuxiang;
hh=zeros(m+2,n+2);
canzhao=zeros(m+2,n+2);
canzhao(2:m+1,2:n+1)=shurutuxiang(:,:);
hh(2:m+1,2:n+1)=shurutuxiang(:,:);
for i=1:caijianshu
for j=2:n+1
if hh(i,j)~=0&sum(sum(hh(i-1:i+1,j-1:j+1)))<=2&sum(sum(caijian(i-1:i+1,j-1:j+1)))<=4
shurutuxiang(i-1,j-1)=0;
end
end
end
hh(2:m+1,2:n+1)=shurutuxiang(:,:);
shuchutuxiang=shurutuxiang;

function lvbo(h1,d)

for i=1:2
[g,num]=bwlabel(h1,4);
for i=1:num
[r,c]=find(bwlabel(h1)--i);
area=numel(r);
if area<d|(max(r)-min(r)<50
h1(r,c)=0;
end
end
end
h=h1;
function hh=lvboo(h1,d)

for i-1:2
[g,num]=bwlabel(h1,4);
for i=1:2
[r,c]=find(bwlabel(h1)==i);
area=numel(r);
if area<d|((max(r)-min(r))<d
h1(r,c)=0;
end
end
end
hh=h1;
function hh= fangxiangfengge6(tuxiang,t)

d=[];
tt=4;
%t=14;
[m,n]=size(tuxiang);
kuozhantu=zeros(m+2*tt,tt+1:n+tt*2);
junzhi=zeros(1,8);
diff=zeros(1,4);
kuozhantu=(tt+1:m+tt,yy+1:n+tt) = tuxiang(:,:);
kongjuzhen1=zeros(m,n);
kongjuzhen2=zeros(m,n);
kongjuzhen3=zeros(m,n);

shuchutuxiang = zeros(m,n);

fangxiang(:,:,1)=[0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
3 0 -1 0 -4 0 -1 0 3;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
];
fangxiang(:,:,5)=fangxiang(:,:,1)';

fangxiang(:,:,2)=[0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
3 0 0 0 0 0 0 0 0 ;
0 0 -1 0 0 0 0 0 0 ;
0 0 0 0 -4 0 0 0 0;
0 0 0 0 0 0 -1 0 0 ;
0 0 0 0 0 0 0 0 3 ;
0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 ;
];
fangxiang(:,:,4)=fangxiang(:,:,2)';

fangxiang(:,:,3)=[3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en(i-t:i+t,j-t:j+t)-ave).^2)))/((2*t+1).^2);
if kongjuzhen1(i-t,j-t)>=ave
kongjuzhen3(i-t,j-t)=1;
else
kongjuzhen3(i-t,j-t)=0;
end
end
end
end
shuchu=kongjuzhen3;
function shuchu=xuanzhuanhuangdiejia(shuchu,du)
shuchu1=zeros(size(shuchu));
for c=-du:du
k=imromate(shuchu,c,'bilinear','crop');
[r,c]=size(k);
for i=1:r
for j=1:c
if k(i,j)>0
shuchu1(i,j)=1;
end
end
end
end
shuchu=shuchu1;
function ll=tongji(low,row,lo,ho)

ll=0;
[ceshi,m,n]=leichuli(low,row);
shuchu2=double(size(m,n));
shuchu2(:,:)=ceshi(:,:);
%figure,imshow(shuchu2);
shuchu1=zeros(m,n);
shuchu3=zeros(m,n);
f2=double(zeros(m,n));
[ceshi,m,n]=leichuli(lo,ho);
shuchu(:,:)=ceshi(:,:);
shuchu1=xuanzhuangdiejia(shuchu,2);
se=strel('square',1);
shuchu1=imdilate(shuchu1,se);
%imshow(shuchu1);
x=[1/9.5 1/9.5 1/9.5;
1/9.5 1/9.5 1/9.5;
1/9.5 1/9.5 1/9.5;];
g=imfilter(shuchu1,double(x),'conv','replicate');
piyi1=pingyi(-1,-1,g,shuchu2,shuchu);
piyi2=pingyi(-0,0,g,shuchu2,shuchu);
piyi3=pingyi(1,1,g,shuchu2,shuchu);
piyi4=pingyi(2,2,shuchu2,shuchu);
piyi5=pingyi(-2,-2,shuchu2,shuchu);
piyi6=pingyi(1,-2,shuchu2,shuchu);
piyi7=pingyi(-2,1,shuchu2,shuchu);
piyi8=pingyi(-1,0,shuchu2,shuchu);
l1=max(max(piyi1,piyi2),max(piyi3,piyi4));
l2=max(max(piyi5,piyi6),max(piyi7,piyi8));
l1=max(l1,l2);

function shuchu=tianchong(shuru,are)

k=~shuru;
[g,num]=bwlabel(k,4);
for i=1:2
for i=1:num
[r,c]=find(bwlabel(k)==i);
area=bwarea(find(bwlabel(k)==i));
if area<are
k(r,c)=0;
end
end
end
shuchu=~k;

function shibielv
load('D:\Program Files\MATLAB\R2011a\ceshi\data3.mat','count1','x1','count2','x2')
tmax=max(max(x1),max(x2));
tmin=min(min(x1),min()x2);
count1=count1*250;
count2=count2*250;
summ2=0;
for i=1:numel(x2)
if x2(i)<0.453
summ2=summ+count2(i);
end
end

function ROC()

load('D:\Program Files\MATLAB\R2011a\ceshi\data3.mat','count1','x1','count2','x2');
tmax=max(max(x1),max(x2));
tmin=min(min(x1),min()x2);
count1=count1*250;
count2=count2*250;
p=0;
r=0:0.001:0;
low=length(r);
far=zeros(1,low);
frr=zeros(1,low);
for t= 0.2:0.001:0.8
p=p+1;
far(p)=sum(count1(x1>=t)/sum(count1));
frr(p)=sum(count2(x2<t))/(sum(count1)+sum(count2));

end
%sum(count1(x1<0.63));sum(count2(x2>=0.63));plot(far*100,frr*100,':');
%画ROC线
hold on
plot(far*100,frr*100,':');
hold on
plot(r,r,':');
%计算识别率;阈值去T的识别率计算
T=0.43;
shibielvn=(sum(count2(x2>=T)))/sum(count2);
shibielv1=(sum(count1(x1<T))+(sum(count2(x2>=T))))/(sum(count1)+sum(count2));
figure,plot(x1,count1/100,':',x2,sount2/100)

function pinyi=pingyi(x,y,shuru,shuchu2,shuchu1)
[m,n]=size(shuchu2);
f2=zeros(m,n);
s=[1 0 0;
0 1 0;
x y 1];
tform=maketform('affine',double(s));
g=imtransform(shuru,tform,'XData',[1,n],'Fillvalue',0);
%imshow(g) k=lvbo(shuchu,400);
for i=1:m
for j=1:n
if g(i,j)~=0&shuchu2(i,j)~=0
f2(i,j)=0;
end
end
end
pinyi=sum(sum(f2))/sum(summ(shuchu2));

function[c]=juzhilvbo(j,k)
[m,n]=size(j);
b=zeros(m+2*k,n+2*k);
b(k+1:m+k,k+1:n+k)=double(j(:,:));
c=zeros(m,n);
for i=k+1:m+k
for j=k+1:n+k
b(i,j)=sum(sum(b(i-k:i+k,j-k:j+k)))/((2*k+1).^2);
end
end
c(:,:)=b(k+1:m+k,k+1:n+k);
%figure,imshow(h,shuru);

function jiboo(q,f,thina,N)
moban=zeros(N,N);
for ll=1:N
for jj=1:N
l=ll-((N-1)/2+1);
j=jj-((N-1)/2+1);

moban(ll,jj)=1/(2*pi*(q.^2))*exp(-(l.^2+j.^2)/(2*q.^2))*exp(i*2*pi*f*(l*cos(thita)+j*sin(thita));
end
end
shuchu=real(moban);

function shuchu=jibofenge(tuxiang)

tuxiang=double(tuxiang);
[m,n]=size(tuxiang);
tu=zeros(m,n);
shuchu=jiboo(1.5179,0.1116,4*pi/8.25);
tu=imfilter(tuxiang,double(shuchu),'conv','replicate');
%tu=histeq(tu);
%
tu=fangxiangfenge6(tu,9);
%tu=fenge(tu,6);
shuchu=tu;
%figure,imshow(tu);

function shuchu=guiyihua(shuru)
shuru=rgb2gray(shuru);
h=fspecial('average');
shuru1=filter2(h,shuru);
[BW2,tv]=edge(double(shuru1),'sobel','vertical');
se=strel('disk',2);
BW2=imclose(BW2,se);
BW2=bwmorph(BW2,'thin',Inf);
BW2=lvboo(BW2,250);
[minl,max1]=bianjie(BW2);
[m,n]=size(k);
s=[double(64/n) 0 0;
0 double(96/n) 0;
0 0 1];
tform=maketform('affine',double(s));
k=imtransform(k,tform,'XData',[1,64],'YData',[1,96],'FillValue',0);
[m,n]=size(k);
p=max(max(k(:,:)))-min(min(k(:,:)));
y=double(256/double(p));
k(:,:)=double((double(y)*double((k(:,:)-min(min(k(:,:)))))));
shuchu=k;
...全文
808 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

249

社区成员

发帖
与我相关
我的任务
社区描述
其他产品/厂家
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧