版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1.色彩空间转换function r,g=rgb_RGB(Ori_Face)R=Ori_Face(:,:,1);G=Ori_Face(:,:,2);B=Ori_Face(:,:,3);R1=im2double(R);% 将 uint8 型转换成 double 型G1=im2double(G);B1=im2double(B);RGB=R1+G1+B1;row=size(Ori_Face,1);% 行像素column=size(Ori_Face,2);% 列像素for i=1:rowfor j=1:columnrr(i,j)=R1(i,j)/RGB(i,j);gg(i,j)=G1(i,j)/RGB
2、(i,j);endendrrr=mean(rr);r=mean(rrr);ggg=mean(gg);g=mean(ggg);2.均值和协方差皮肤库 1.jpg');r1,g1=rgb_RGB(t1);皮肤库 2.jpg');r2,g2=rgb_RGB(t2);皮肤库 3.jpg');r3,g3=rgb_RGB(t3);皮肤库 4.jpg');r4,g4=rgb_RGB(t4);皮肤库 5.jpg');r5,g5=rgb_RGB(t5);皮肤库 6.jpg');r6,g6=rgb_RGB(t6);皮肤库 7.jpg');r7,g7=rgb_
3、RGB(t7);皮肤库 8.jpg');r8,g8=rgb_RGB(t8);3d皮肤库 9.jpg');r9,g9=rgb_RGB(t9);皮肤库 10.jpg');r10,g10=rgb_RGB(t10);皮肤库 11.jpg');r11,g11=rgb_RGB(t11);皮肤库 12.jpg');r12,g12=rgb_RGB(t12);皮肤库 13.jpg');r13,g13=rgb_RGB(t13);皮肤库 14.jpg');r14,g14=rgb_RGB(t14);皮肤库 15.jpg');r15,g15=rgb_RGB
4、(t15);皮肤库 16.jpg');r16,g16=rgb_RGB(t16);皮肤库 17.jpg');r17,g17=rgb_RGB(t17);皮肤库 18.jpg');r18,g18=rgb_RGB(t18);皮肤库 19.jpg');r19,g19=rgb_RGB(t19);皮肤库 20.jpg');r20,g20=rgb_RGB(t20);皮肤库 21.jpg');r21,g21=rgb_RGB(t21);皮肤库 22.jpg');r22,g22=rgb_RGB(t22);皮肤库 23.jpg');r23,g23=rgb
5、_RGB(t23);皮肤库 24.jpg');r24,g24=rgb_RGB(t24);皮肤库 25.jpg');r25,g25=rgb_RGB(t25);皮肤库 26.jpg');r26,g26=rgb_RGB(t26);皮肤库 27.jpg');r27,g27=rgb_RGB(t27);r=cat(1,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r25,r26,r27);g=cat(1,g1,g2,g3,g4,g5,g6,g7,g
6、8,g9,g10,g11,g12,g13,g14,g15,g16,g17,g18,g19,g20,g21,g22,g23,g24,g25,g26,g27);m=mean(r,g)n=cov(r,g)3.求质心function xmean, ymean = center(bw)bw=bwfill(bw,'holes');area = bwarea(bw);3dm n =size(bw);bw=double(bw);xmean =0; ymean = 0;for i=1:m,for j=1:n,xmean = xmean + j*bw(i,j);ymean = ymean + i*
7、bw(i,j);end;end;if(area=0)xmean=0;ymean=0;elsexmean = xmean/area;ymean = ymean/area;xmean = round(xmean);ymean = round(ymean);end4. 求偏转角度function theta = orient(bw,xmean,ymean)m n =size(bw);bw=double(bw);a = 0;b = 0;c = 0;for i=1:m,for j=1:n,a = a + (j - xmean)2 * bw(i,j);b = b + (j - xmean) * (i -
8、ymean) * bw(i,j);c = c + (i - ymean)2 * bw(i,j);3dend;end;b = 2 * b;theta = atan(b/(a-c)/2;theta = theta*(180/pi);% 从幅度转换到角度5. 找区域边界function left, right, up, down = bianjie(A)m n = size(A);left = -1;right = -1;up = -1;down = -1;for j=1:n,for i=1:m,if (A(i,j) = 0)left = j;break;end;end;if (left = -1)
9、 break;end;end;for j=n:-1:1,for i=1:m,if (A(i,j) = 0)right = j;break;end;end;if (right = -1) break;end;3dend;for i=1:m,for j=1:n,if (A(i,j) = 0)up = i;break;end;end;if (up = -1)break;end;end;for i=m:-1:1,for j=1:n,if (A(i,j) = 0)down = i;break;end;end;if (down = -1)break;end;end;6. 求起始坐标function new
10、coord = checklimit(coord,maxval)newcoord = coord;if (newcoord<1)newcoord=1;end;3dif (newcoord>maxval)newcoord=maxval;end;7.模板匹配function ccorr, mfit, RectCoord = mobanpipei(mult, frontalmodel,ly,wx,cx, cy, angle)frontalmodel=rgb2gray(frontalmodel);model_rot = imresize(frontalmodel,ly wx,'bi
11、linear'); %调整模板大小model_rot = imrotate(model_rot,angle,'bilinear');% 旋转模板l,r,u,d = bianjie(model_rot);% 求边界坐标bwmodel_rot=imcrop(model_rot,l u (r-l) (d-u);% 选择模板人脸区域modx,mody =center(bwmodel_rot);% 求质心morig, norig = size(bwmodel_rot);% 产生一个覆盖了人脸模板的灰度图像mfit = zeros(size(mult);mfitbw = zeros
12、(size(mult);limy, limx = size(mfit);% 计算原图像中人脸模板的坐标startx = cx-modx;starty = cy-mody;endx = startx + norig-1;endy = starty + morig-1;startx = checklimit(startx,limx);starty = checklimit(starty,limy);endx = checklimit(endx,limx);endy = checklimit(endy,limy);for i=starty:endy,for j=startx:endx,mfit(i,
13、j) = model_rot(i-starty+1,j-startx+1);end;end;3dccorr = corr2(mfit,mult)% 计算相关度l,r,u,d = bianjie(bwmodel_rot);sx = startx+l;sy = starty+u;RectCoord = sx sy (r-1) (d-u); % 产生矩形坐标8.主程序clear;fname,pname=uigetfile('*.jpg''*.bmp''*.tif''*.gif','Please choose a colorpic
14、ture.');% 返回打开的图片名与图片路径名u,v=size(fname);y=fname(v); % 图片格式代表值 switch ycase 0errordlg('You Should Load Image File First.','Warning.');case'g''G''p''P''f''F' % 图片格式若是 JPG/jpg、 BMP/bmp、 TIF/tif 或者 GIF/gif ,才打开I=cat(2,pname,fname);Ori_F
15、ace=imread(I);subplot(2,3,1),imshow(Ori_Face);otherwiseerrordlg('You Should Load Image File First.','Warning.');endR=Ori_Face(:,:,1);G=Ori_Face(:,:,2);B=Ori_Face(:,:,3);R1=im2double(R);% 将 uint8 型转换成 double 型处理G1=im2double(G);B1=im2double(B);RGB=R1+G1+B1;m= 0.4144,0.3174;% 均值n=0.0031
16、,-0.0004;-0.0004,0.0003;% 方差3drow=size(Ori_Face,1);% 行像素数column=size(Ori_Face,2);% 列像素数for i=1:rowfor j=1:columnif RGB(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)');% 皮肤概率服从高斯分布endendendsubplot(2,3
17、,2);imshow(p);% 显示皮肤灰度图像low_pass=1/9*ones(3);image_low=filter2(low_pass, p);% 低通滤波去噪声subplot(2,3,3);imshow(image_low);% 自适应阀值程序previousSkin2 = zeros(i,j);changelist = ;for threshold = 0.55:-0.1:0.05two_value = zeros(i,j);two_value(find(image_low>threshold) = 1;change = sum(sum(two_value - previou
18、sSkin2);changelist = changelist change;previousSkin2 = two_value;endC, I = min(changelist);optimalThreshold = (7-I)*0.1two_value = zeros(i,j);3dtwo_value(find(image_low>optimalThreshold) = 1;% 二值化subplot(2,3,4);imshow(two_value);% 显示二值图像我的照片 人脸模板 .jpg');% 读入人脸模板照片FaceCoord=;imsourcegray=rgb2g
19、ray(Ori_Face);% 将原照片转换为灰度图像L,N=bwlabel(two_value,8);% 标注二值图像中连接的部分,L 为数据矩阵,N 为颗粒的个数for i=1:N,x,y=find(bwlabel(two_value)=i);% 寻找矩阵中标号为i 的行和列的下标bwsegment = bwselect(two_value,y,x,8);% 选择出第 i 个颗粒numholes = 1-bweuler(bwsegment,4);% 计算此区域的空洞数if (numholes >= 1)% 若此区域至少包含一个洞,则将其选出进行下一步运算RectCoord = -1;
20、m n = size(bwsegment);cx,cy=center(bwsegment);% 求此区域的质心bwnohole=bwfill(bwsegment,'holes');% 将洞封住(将灰度值赋为1)justface = uint8(double(bwnohole) .* double(imsourcegray);% 只在原照片的灰度图像中保留该候选区域angle = orient(bwsegment,cx,cy);% 求此区域的偏转角度bw = imrotate(bwsegment, angle, 'bilinear');bw = bwfill(bw
21、,'holes');l,r,u,d =bianjie(bw);wx = (r - l +1);% 宽度ly = (d - u + 1);% 高度wratio = ly/wx% 高宽比if (0.8<=wratio)&(wratio<=2)3d% 如果目标区域的高度 /宽度比例大于 0.8 且小于 2.0,则将其选出进行下一步运算S=ly*wx;% 计算包含此区域矩形的面积A=bwarea(bwsegment);% 计算此区域面积if (A/S>0.35)ccorr,mfit, RectCoord = mobanpipei(justface,fronta
22、lmodel,ly,wx,cx,cy, angle);endif (ccorr>=0.6)mfitbw=(mfit>=1);invbw = xor(mfitbw,ones(size(mfitbw);source_with_hole = uint8(double(invbw) .* double(imsourcegray); final_image = uint8(double(source_with_hole) + double(mfit);subplot(2,3,5);imshow(final_image);% 显示覆盖了模板脸的灰度图像imsourcegray = final_
23、image;subplot(2,3,6);imshow(Ori_Face); % 显示检测效果图 end;if (RectCoord = -1)FaceCoord = FaceCoord; RectCoord;endendendend% 在认为是人脸的区域画矩形numfaces x = size(FaceCoord); for i=1:numfaces,hd = rectangle('Position',FaceCoord(i,:); set(hd, 'edgecolor', 'y');end3d人脸检测是人脸识别、人机交互、智能视觉监控等工作的
24、前提。近年来,在模式识别与计算机视觉领域 ,人脸检测己经成为一个受到普遍重视、研究十分活跃的方向。本文针对复杂背景下的彩色正面人脸图像,将肤色分割、模板匹配与候选人脸图像块筛选结合起来,构建了人脸检测实验系统 ,并用自制的人脸图像数据库在该系统下进行了一系列的实验统计。本文首先介绍了人脸检测技术研究的背景和现状,阐明人脸检测技术发展的重要意义,对目前常用的一些检测算法进行了总结,然后着重阐述了基于肤色分割和模板匹配验证的人脸检测算法。肤色是人脸重要特征 ,在通过肤色采样统计和聚类分析后,确立一种在YCbCr空间下的基于高斯模型的肤色分割方法。在YCbCr色彩空间中建立肤色分布的高斯模型,得到肤色概率似然图像 ,在最佳动态阈值选取算法下完成肤色区域的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新员工培训财务规章制度
- 旅店安全教育培训制度
- 春秋战国审计制度
- 期期权风控制度
- 机关单位内部审计制度
- 机电科绩效考核制度
- 村社干部绩效考核制度
- 杭州消防员绩效考核制度
- 校园安保教育培训制度
- 武警消防财务规章制度
- 《先兆流产中西医结合诊疗指南》
- MySQL数据库原理及应用 教学大纲 及 课后习题答案(王坚)
- 2025年度民办非企业单位工作计划
- 《植物生产与环境》考试复习题库
- 【八年级上册地理】一课一练2.2 世界的气候类型 同步练习
- 大学生魅力讲话实操学习通超星期末考试答案章节答案2024年
- 《游园》课件统编版高中语文必修下册
- 【盒马鲜生冷供应链物流成本现状、问题及优化建议探析11000字(论文)】
- HG/T 22820-2024 化工安全仪表系统工程设计规范(正式版)
- 基于人工智能的文化遗产保护与传承策略
- 2022年上海市养老服务综合统计监测报告
评论
0/150
提交评论