基于gabor特征提取和SVM支持向量机的人脸识别matlab仿真

目录

一、理论基础

二、核心程序

三、仿真结论


一、理论基础

        这里,关于图片特征的提取,请先看这次我们补充发你的garbor特征提取论文,我们是利用garbor变换进行特征提取的。以二维形式存在的人脸图像所包含的数据信息是非常多的,而且,这些数据中还包含了很多与人身份并没有多少关系的冗余信息,例如,表情、光线条件等。因此,不能将这些数据直接作为人脸的代表特征来进行识别,也就是必须首先进行特征提取。特征提取的定义为:当原始特征的数量很大,或者说样本是处于一个高维空间中的向量时,通过映射(或变换)的方法用低维空间来表示。如上所述,由于人脸的维数在通常情况下很高,特征提取的成败就对整个识别阶段的效果有决定性的影响。甚至可以这样认为:在某种意义上,人脸识别过程的成败就决定于特征提取的好坏,因此,如何有效的进行特征提取就成为人脸识别科研人员不得不面对的关键性问题。鉴于特征提取的重要性,也有人将它独立作为整个人脸识别过程中的一个阶段。这里,其主要操作时提取特征,并将特征结果向量化,使二维的特征矩阵变为一维的特征向量,从而方便操作。

        首先,这里面的数据gabor特征数据,具体的理论要看这次提供给你的文献(之前没有给你)

其主要的思想是这样的:

首先要了解二维的gabor函数:

这里的feature就是根据gabor函数得到的特征参数组。这个参数是用来在提取特征的时候,参与运算的。

       SVM是20世纪90年代由Vapnik等人提出的,来源于统计学习理论的一种新的数据分类技术。其主要思想就是通过一个非线性变换将原始的数据变换到一个高维的特征空间,并在新的空间实现最优分类。

        上述的最优分类函数其最终的分类判别函数以及它的求解过程只涉及样本之间的内积运算。可见,要解决一个特征空间中的最优线性分类问题,只需知道这个空间的内积运算即可。 

二、核心程序

function images_facefind = func_facefind(net,images,Nums2);


%注意,这个参数和训练库的头像图片的大小相关
len_pixel = round(19/2)-1;
%计算图片的大小
[rr,cc]=size(images);
%判决门限
levels = Nums2;
%人脸模板
tmp_face1 = 'Library_picture\TRAIN\temp\1.png';      
tmp_face2 = 'Library_picture\TRAIN\temp\2.png';      
%计算每个图片的最大值
Image1 = double(images);
maxs   = max(max(Image1));
mins   = min(min(Image1));
C1     = ((Image1-mins)/(maxs-mins) - 0.5) * 2;
Image2 = double(imread(tmp_face1));
maxs   = max(max(Image2));
mins   = min(min(Image2));
C2     = ((Image2-mins)/(maxs-mins) - 0.5) * 2;
Image3 = double(imread(tmp_face2));
maxs   = max(max(Image3));
mins   = min(min(Image3));
C3     = ((Image3-mins)/(maxs-mins) - 0.5) * 2;
%识别参数初始化
Cell.state                       =  int8(imregionalmax(double(conv2(C1,C2,'same')))|imregionalmax(double(conv2(C1,C3,'same'))));
Cell.state(1:len_pixel,:)        = -1;
Cell.state(end-len_pixel:end,:)  = -1;
Cell.state(:,1:len_pixel)        = -1;
Cell.state(:,end-len_pixel:end)  = -1;
Cell.net                         = -1*ones(rr,cc);

%进行无限循环,搜索和神经网络匹配的区域
while(1==1)
    [i,j]=find(Cell.state==1,1);
    %搜索完毕,则退出循环
    if isempty(i)break;end
    %搜索人脸区域
    face_areas       = images(i-len_pixel:i+len_pixel,j-len_pixel:j+len_pixel);
    Cell.state(i,j)  = -1;
    %通过神经网络进行测试预测
    Cell.net(i,j)    = sim(net,func_image_feature(face_areas));   
    if  Cell.net(i,j) < -0.95
                for i2=i-3:i+3
                    for j2=j-3:j+3
                        try Cell.state(i2,j2)=-1;end
                    end
                end 
                continue;    
            elseif Cell.net(i,j) < -1*levels continue;
            elseif Cell.net(i,j) > 0.95
                for i2=i-len_pixel:i+len_pixel
                    for j2=j-len_pixel:j+len_pixel
                        try Cell.state(i2,j2)=-1;end
                    end
                end
            elseif Cell.net(i,j) > levels
            elseif Cell.net(i,j) < levels     
    end   
    %======================================================================
    for i4=-1:1
        for j4=-1:1
                    i3=i+i4;                    
                    j3=j+j4;            
                    if (Cell.state(i3,j3) == -1 || Cell.net(i3,j3)~=-1)continue;end          
                    face_areas      = images(i3-len_pixel:i3+len_pixel,j3-len_pixel:j3+len_pixel);
                    Cell.net(i3,j3) = sim(net,func_image_feature(face_areas));
                    if Cell.net(i3,j3) > 0.95
                        for i2=i3-len_pixel:i3+len_pixel
                            for j2=j3-len_pixel:j3+len_pixel
                                try
                                    Cell.state(i2,j2)=-1;
                                end
                            end
                        end
                        continue;
                    end           
                    if Cell.net(i3,j3) > levels
                        Cell.state(i3,j3) = 1;
                    else
                        Cell.state(i3,j3) = -1;
                    end  
        end
    end
    %======================================================================
end
[MM,aresxy_number]   = bwlabeln(imdilate(imregionalmax(Cell.net > levels),strel('disk',2,4)),4);
CentroidMatrix       = regionprops(MM,'centroid');
aresxy               = zeros(rr,cc);
for i = 1:aresxy_number
    aresxy(fix(CentroidMatrix(i).Centroid(2)),fix(CentroidMatrix(i).Centroid(1))) = 1;
end
aresxy                 = func_recs(aresxy,[19 19],len_pixel);
images_facefind(:,:,1) = images;
images_facefind(:,:,2) = images;
images_facefind(:,:,3) = images;
for i = 1:rr
    for j=1:cc
        if aresxy(i,j)==1
            images_facefind(i,j,1)=255;
            images_facefind(i,j,2)=255;
            images_facefind(i,j,3)=0;       
        end
    end
end
A10-16

三、仿真结论

猜你喜欢

转载自blog.csdn.net/ccsss22/article/details/129965307