资源简介

使用Gabor滤波器达到人眼识别定位的目的 效果还行

资源截图

代码片段和文件信息

clear all;
clc;

I=imread(‘E:\course\图像处理与模式识别\final project\Test images\test_image_1.jpg‘);
I=rgb2gray(I);           %灰度变换
figure(1); imshow(I);

J=I;
[mn]=size(J);
if isa(J‘double‘)~=1
   J=double(J);
end

M=5; %gabor滤波器有5个尺度
X=16; %gabor滤波器窗口大小
Y=16;
gb=getGaborKernels(MXY);
gabor_real=conv2(Jreal(gb(::1))‘same‘);    %返回和J大小相同的卷积
gabor_imag=conv2(Jimag(gb(::1))‘same‘);
f=sqrt(gabor_real.*gabor_real+gabor_imag.*gabor_imag);   %平方根    .*矩阵乘法
f=(f-min(f(:))) / (max(f(:))-min(f(:)));
figure(2); imshow(f);
%  边沿亮点涂黑
f(1:10:)=0;
f(m-10:end:)=0;
f(m/2+1:2*m/3:)=0;
figure(3);
imshow(f);
k=f;
t=k(1:m/21:n/2);
max_t=max(t(:));   %返回最大值
k(1:m/21:n/2)=k(1:m/21:n/2)>0.45*max_t;
t=k(1:m/2n/2+1:end);
max_t=max(t(:));
k(1:m/2n/2+1:end)=k(1:m/2n/2+1:end)>0.45*max_t;
t=k(2*m/3+1:end:);
max_t=max(t(:));
k(2*m/3+1:end:)=k(2*m/3+1:end:)>0.45*max_t;
k(m/2+1:end:)=0;
figure(4);imshow(k);


se = strel(‘square‘5);    %宽度为5的窗口
k = imdilate(kse);        %膨胀
figure(5);
imshow(k);
k(1:15:)=0;


%%  left eye 
BW=k(1:m/21:n/2);    %认为给的图片就是正面人脸
[Lnum]=bwlabel(BW);  %num中存放联通域的个数
max_area=0;min_r=0;max_r=0;min_c=0;max_c=0;
for p=1:num
    [rc]=find(L==p);
    mn_r=min(r);
    mx_r=max(r);
    mn_c=min(c);
    mx_c=max(c);
    temp=L(mn_r:mx_rmn_c:mx_c);
    curr_area=sum(temp(:)) / p;
    if (curr_area>max_area)
        max_area=curr_area;
        min_r=mn_r;max_r=mx_r;
        min_c=mn_c;max_c=mx_c;
    end
end

center_r=round((min_r+max_r)/2);
center_c=round((min_c+max_c)/2);
% add %
fprintf(‘左眼:[%d%d]\n‘center_rcenter_c);     %中心点坐标
I(center_r-17:center_r-15center_c-17:center_c+17)=255;  %画框框
I(center_r+15:center_r+17center_c-17:center_c+17)=255;
I(center_r-17:center_r+17center_c-17:center_c-15)=255;
I(center_r-17:center_r+17center_c+15:center_c+17)=255;


%% right eye %%%%
BW=k(1:m/2n/2+1:n);
[Lnum]=bwlabel(BW);
max_area=0;min_r=0;max_r=0;min_c=0;max_c=0;
for p=1:num
    [rc]=find(L==p);
    mn_r=min(r);
    mx_r=max(r);
    mn_c=min(c);
    mx_c=max(c);
    temp=L(mn_r:mx_rmn_c:mx_c);
    curr_area=sum(temp(:)) / p;
    if (curr_area>max_area)
        max_area=curr_area;
        min_r=mn_r;max_r=mx_r;
        min_c=mn_c;max_c=mx_c;
    end
end

center_r=round((min_r+max_r)/2);
center_c=round((min_c+max_c)/2);
fprintf(‘右眼:[%d%d]\n‘center_rn/2+center_c);

I(center_r-17:center_r-15n/2+center_c-17:n/2+center_c+17)=255;
I(center_r+15:center_r+17n/2+center_c-17:n/2+center_c+17)=255;
I(center_r-17:center_r+17n/2+center_c-17:n/2+center_c-15)=255;
I(center_r-17:center_r+17n/2+center_c+15:n/2+center_c+17)=255;



figure(6); imshow(I);


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

     文件       3019  2012-01-06 13:18  eyeLocation.asv

     文件       2806  2012-01-06 13:19  eyeLocation.m

     文件        269  2011-05-18 23:12  gabor.m

     文件        286  2011-05-18 23:12  getGaborKernels.m

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

                 6380                    4


评论

共有 条评论