natalie

基于肤色特征的人脸识别

1、色彩空间转换

2、根据肤色模型转换为二值图像

3、利用腐蚀运算和开运算对图像进行重构

4、消除噪声

5、断开连接处理

6、边缘检测

由于没有实验用的图片,所以就只能贴程序了

程序如下

%读入图片并显示
img=imread(\'biye.jpg\');
imshow(img)
%对读入的图像进行色彩空间的转换
f = rgb2ycbcr(img);
%利用皮肤的色彩模型对图像进行二值化处理
f_cb=f(:,:,2);
f_cr=f(:,:,3);
f = (f_cb>=100) & (f_cb<=127) & (f_cr>=138) &(f_cr<=170) ;
figure; imshow(f);
%利用数学形态学对输入的图像进行去噪
se=strel(\'square\',3);
f=imopen(f,se);
f=imclose(f,se);
figure(2),imshow(f);
f=imfill(f,\'holes\');
figure(3),imshow(f);
% 对图像进行重构
fe=imerode(f,ones(8,7));
fo=imopen(f,ones(8,7));
f=imreconstruct(fe,f);
 figure(4),imshow(f);
se1=strel(\'square\',8);
f=imerode(f,se1);
f=imdilate(f,se1);
figure(6),imshow(f);
% 限定条件程序

[L,num]=bwlabeln(f,4);
for i=1:num;
    [r,c]=find(L==i);
    r_temp=max(r)-min(r);
    c_temp=max(c)-min(c);
    temp=size(r);
    area_sq=r_temp*c_temp;
    area=size(find(L==i),1);
    ratio=area/area_sq;
    if (r_temp/c_temp<0.8)|(r_temp/c_temp>2)|temp(1)>2000|temp(1)<200 |ratio<0.6     
      for j=1:temp(1);
        L(r(j),c(j))=0;
        end
    else
        continue;
    end
end
%对图像进行边缘检测
L=bwperim(L,8); 
L=uint8(L);
z=find(L(:)>0);
L(z)=255;
figure(7),imshow(L);
L_r=L;
L_g=L;
L_b=L;
L_rgb=cat(3,L_r,L_g,L_b); 
% 显示最终结果
img1_r=min(L_r+img(:,:,1),255);
img1_g=min(L_g+img(:,:,2),255);
img1_b=min(L_b+img(:,:,3),255);
img1=cat(3,img1_r,img1_g,img1_b);
figure(8),imshow(img1);

 

分类:

技术点:

相关文章: