• 大小: 1.45MB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2024-02-02
  • 语言: Matlab
  • 标签: 人脸识别  

资源简介

人脸识别,MATLAB源码,matlab人脸识别,基于matlab的人脸识别

资源截图

代码片段和文件信息

clear all
close all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 读入待检测图像
x= imread(‘boy1.bmp‘);
xx=x;
figureimshow(x); %RGB

fR=xx(::1);
fG=xx(::2);
fB=xx(::3);
figureimshow(fR); % r gray 
f=1/9*ones(3);%低通滤波器,滤除高频噪声 
filtered_fR=imfilter(fRf);
filtered_fG=imfilter(fGf);
filtered_fB=imfilter(fBf);

figureimshow(filtered_fR); % r gray filter

x_filtered=cat(3filtered_fRfiltered_fGfiltered_fB);
figureimshow(x_filtered); %rgb filter


I=rgb2ycbcr(x);        %颜色空间转换  Ycbcr
figureimshow(I);

gray=rgb2gray(x);  %gray
figureimshow(gray);

[abc]=size(I); %得到图像的像素点个数
Iy = I(::1);
Icb = I(::2);
Icr = I(::3);
figureimshow(Icb);
title(‘Icr‘);
%display(c);
cb=double(I(::2));
%display(cb);
cr=double(I(::3));
for i=1:a   %240
    for j=1:b %320
        w=[cb(ij)cr(ij)];
        m=[117.4316 148.5599];
        n=[260.1301 12.1430;12.1430 150.4574];
        p(ij)=exp((-0.5)*(w-m)*inv(n)*(w-m)‘);%算某象素点的概率
        if (p(ij)<0.5) 
            p(ij)=0;
        else 
            p(ij)=1;
        end
    end
end 
fenge=p;
figure
imshow(fenge);

SE = strel(‘square‘3); 
imf=imopen(pSE);         %开运算(即先腐蚀再膨胀),消除杂散点 
xingtai=imf;
figure
imshow(xingtai);
%figureimshow(Ibwopen); 
%Ibwoc=imclose(IbwopenSE);      %闭运算,去掉由于开运算引入的许多缺口 
%figureimshow(Ibwoc); 
%imf=imfill(Ibwoc‘holes‘);      %填充孔洞 
%%%%%%%%%%%%%%%%%%%%%%%根据填充率去除手脚、胳膊等非人脸区域%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Lnum]=bwlabel(imf8);     %连通区域标记 
B=zeros(size(imf));
for i=1:num
    Area(i)=bwarea(L==i);%计算每个皮肤区域的面积
end
for i=1:num
    [rc] = find(L==i) ;
    left(i)=min(c);
    right(i)=max(c);
    up(i)=min(r);
    down(i)=max(r);
end
for i=1:num 
    %计算各矩形区域面积
    Rect_Area(i)=(down(i)-up(i))*(right(i)-left(i));
end
%计算各区域的填充率
Ratio=Area./Rect_Area;
for i=1:num 
   if Ratio(i)>=0.5%若相应区域的填充率大于0.5则保留该区域
       [xy]=find(L==i);%第i块区域的坐标值
       B=B+bwselect(imfyx8);%把填充率大于0.5皮肤区域叠加起来   
   end      
end
%%%%%%%%%%%%%%%%%%%%%%%%%%根据面积比来进一步除去一些较小的非人脸区域%%%%%%%%%%%%%%%%%%%%%%%%%%
[L1num1]=bwlabel(B8);     %连通区域标记
B1=zeros(size(B));
for i=1:num1
    Area(i)=bwarea(L1==i);%计算每个皮肤区域的面积
end
maxarea=max(Area);%取最大值
q=Area/maxarea;%每块区域的面积与最大区域面积的比值   
for i=1:num1 
   if q(i)>=0.3%若相应区域的面积比值大于0.3则保留该区域
       [xy]=find(L1==i);%第i块区域的坐标值
       B1=B1+bwselect(Byx8);%把面积比值大于0.3皮肤区域叠加起来   
   end      
end
%%%%%%%%%%%%%%%%%%%%%%%%%%根据肤色区域的长宽比来除去一些非人脸区域%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[L2num2]=bwlabel(B18);     %连通区域标记 
B2=zeros(size(B1));
for i=1:num2
    [rc] = find(L2==i);  
    left(i)=min(c);
    right(i)=max(c);
    up(i)=min(r);
    down(i)=max(r);
end
for i=1:num2
    if ((down(i)-up(i))/(right(i)-left(i)))>0.8&((down(i)-up(i))/(right(i)-left(i)))<2
        [xy]=find(L2==i);
        B2=B2+bwselect(B1yx8);%%%把满足长宽比在0.8到2的区域留下
    end
end
figure
imshow(xx);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%把人脸框出来%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[L3 num3]=bwlabel(B28);   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     230454  2012-10-09 10:29  face\boy1.bmp

     文件       3753  2018-03-23 16:25  face\face_idenfication.m

     文件     294966  2012-10-09 10:30  face\girl1.bmp

     文件     230454  2012-10-09 10:29  face\girl2.bmp

     文件     304182  2012-10-09 15:07  face\girl3.bmp

     文件    1133360  2017-11-21 20:26  face\lena1.png

     文件      19259  2018-03-20 19:14  face\mayun.jpg

     目录          0  2018-03-23 17:58  face

----------- ---------  ---------- -----  ----

              2216428                    8


评论

共有 条评论