资源描述:
《基于肤色的简易人脸检测matlab程序.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、基于肤色的简易人脸检测(matlab版)clc;clearall;closeall;%ÔØÈëͼÏñImg=imread('D:renlian6.jpg');R=Img(:,:,1);G=Img(:,:,2);B=Img(:,:,3);R1=im2double(R);%½«uint8ÐÍת»»³ÉdoubleÐÍ´¦ÀíG1=im2double(G);B1=im2double(B);RGB=R1+G1+B1;m=[0.4144,0.3174];%¾ùÖµn=[0.0031,-0.0004;-0.0004,0.0003];%·½²î[x1,y1]=mes
2、hgrid(0:0.01:1,0:0.01:1);a1=sqrt(n(4));a2=sqrt(n(1));r=(-n(2))/(a1*a2);middle1=1./(2.*pi.*a1.*a2.*sqrt(1-r.^2));middle2=((-1)./(2.*(1-r.^2))).*(((x1-m(1))).^2./a1.^2-2.*r.*(x1-m(1)).*(y1-m(2))./(a1.*a2)+(y1-m(2)).^2./a2.^2);z1=middle1.*exp(middle2);figure;subplot(1,2,1);mesh(x1,y1,z
3、1);title('ÀíÏëµÄ·ôÉ«·Ö²¼');row=size(Img,1);%ÐÐÏñËØÊýcolumn=size(Img,2);%ÁÐÏñËØÊýfori=1:rowforj=1:columnifRGB(i,j)==0rr(i,j)=0;gg(i,j)=0;elserr(i,j)=R1(i,j)/RGB(i,j);%rgb¹éÒ»»¯gg(i,j)=G1(i,j)/RGB(i,j);x=[rr(i,j),gg(i,j)];p(i,j)=exp((-0.5)*(x-m)*inv(n)*(x-m)');%Ƥ·ô¸ÅÂÊ·þ´Ó¸ß˹·Ö²¼end
4、endendsubplot(1,2,2);mesh(p);title('ʵ¼Ê·ôÉ«·Ö²¼');ifndims(Img)==3I=rgb2gray(Img);elseI=Img;endJ=imnoise(I,'salt&pepper',0.01);I1=filter2(fspecial('average',3),J,'full')/255;BW=im2bw(I1,graythresh(I1));%¶þÖµ»¯figure;subplot(2,4,1);imshow(Img,[01]);title('Ô-ͼÏñ');subplot(2,4,2);imsh
5、ow(Img,[01]);title('Íø¸ñ±ê¼ÇͼÏñ');holdon;[xt,yt]=meshgrid(round(linspace(1,size(I,1),10)),...round(linspace(1,size(I,2),10)));mesh(yt,xt,zeros(size(xt)),'FaceColor',...'None','LineWidth',3,...'EdgeColor','r');subplot(2,4,3);imshow(p);title('»ùÓÚ·ôÉ«¸ÅÂÊ·Ö²¼µÄ»Ò¶ÈͼÏñ');subplot(2,4,
6、4);imshow(I1);title('ÁÚÓòƽ¾ù·¨Â˲¨ºóͼÏñ');subplot(2,4,5);imshow(BW);title('¶þÖµ»¯ºóͼÏñ');[n1,n2]=size(BW);r=floor(n1/10);%·Ö³É10¿é£¬ÐÐc=floor(n2/10);%·Ö³É10¿é£¬ÁÐx1=1;x2=r;%¶ÔÓ¦Ðгõʼ»¯s=r*c;%¿éÃæ»ýfori=1:10y1=1;y2=c;%¶ÔÓ¦Áгõʼ»¯forj=1:10if(y2<=c
7、
8、y2>=9*c)
9、
10、(x1==1
11、
12、x2==r*10)%Èç¹
13、ûÊÇÔÚËÄÖÜÇøÓòloc=find(BW(x1:x2,y1:y2)==0);[p,q]=size(loc);pr=p/s*100;%ºÚÉ«ÏñËØËùÕ¼µÄ±ÈÀýÊýifpr<=100BW(x1:x2,y1:y2)=0;r1=x1;r2=x2;s1=y1;s2=y2;pr1=0;endendy1=y1+c;%ÁÐÌøÔ¾y2=y2+c;%ÁÐÌøÔ¾endx1=x1+r;%ÐÐÌøÔ¾x2=x2+r;%ÐÐÌøÔ¾end[L,num]=bwlabel(BW,8);%ÇøÓò±ê¼Çstats=regionprops(L,'BoundingBox'
14、);%µÃµ½°üΧ¾ØÐοòBd