|
本人做着 final project - Face recognition,
自己胆粗粗写了个 algorithm,然后用matlab写了出来,
现在放上来,希望大家能帮忙测试..
clear;
clc;
% read image
image = imread('DSC00864.JPG'); % change here for different picture's filename
imagegray1 = rgb2gray(image); %change colored image to grayscale.
figure(1);
test1=imshow(imagegray1);
title('original','fontsize',18)
count=0;
tempx=0;
xmax=0;
blacken=0;
countn=0;
diff=5; % predifined intencity changes in pixel.
y=400;
for n = 1:400
for m = 1:300
%check every pixel, find obvious intensity changes in between neighbouring pixels.
if m<300 && blacken==0
if imagegray1(n,m+1)-imagegray1(n,m)>=diff || imagegray1(n,m+1)-imagegray1(n,m)<=-diff
x1=m;
count=count+1;
if count==1
ymin=n;
end
for m1 = 300:-1:1
if m1>1
if imagegray1(n,m1)-imagegray1(n,m1-1)>=diff || imagegray1(n,m1)-imagegray1(n,m1-1)<=-diff
x2=m1;
tempx=x2-x1;
break;
else
imagegray1(n,m1)=0;
end
end
end
if xmax<tempx
xmax=tempx;
countn=0;
else
countn = countn+1;
end
break;
else
imagegray1(n,m)=0;
end
else
imagegray1(n,m)=0;
end
end
if countn == 20 || n==y
ymax=xmax*1.6; %predefined face ratio, change to get different result
y=int16(ymax);
if n==y
blacken=1;
end
for n2=y:400
for m2=1:300
imagegray1(n2,m2)=0;
end
end
end
end
figure(2);
imshow(imagegray1);
title('Process','fontsize',18)
这个algo主要是'遮'掉其他不要的背景,只拿人的脸部.
用人脸的ratio来找出脸的长度,然后确定要'遮'到图片的那里...
algo等我有空才写,我现在赶着出去..请大家看着我的code comments来试着明白.
请大家用一张纯色背景的人头照(好像passport的照片)帮我试试看,然后告诉我你们的result.最好能够把照片po上来.
当然更希望大家提出意见和建议,让我的algo能更好,现在我对结果很不满意....
非常感谢大家...
感恩... |
|