Face shape Extraction using MATLAB

I want to extract shape of human face like square, oblong etc. Can anyone guide me how should I approach this problem?

Answers (1)

Image Analyst
Image Analyst on 14 Apr 2013
You could use image processing. First find the face, for example with the Computer Vision System Toolbox ( http://www.mathworks.com/products/computer-vision/description4.html), then call regionprops to make the measurements you need.

3 Comments

I have this code but I don't really understand all of it. I am not a pro in MATLAB and I tried googling some commands to see what is going on. Can you explain it to me after the regionprops? I think I need to modify it a bit because it does not work with some images and gives two or more values with some others.
I=imread('girl.jpg');
a=rgb2gray(I); %convert image to grey scale
bw=edge(a,'canny'); % find edges in the grey scale image
bw = bwareaopen(bw,30); %remove small objects from image - extra edges
se = strel('disk',2); %creates a morphological structuring disk element with radius of 2 pixels
bw = imclose(bw,se); % Morpholigically closes the image. The morphological close operation is a dilation followed by an erosion, using the same structuring element for both operations.
bw = imfill(bw,'holes'); %Fill image regions and holes
L = bwlabel(bw); %L = bwlabel(BW, n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW. The variable n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects. If the argument is omitted, it defaults to 8.
s = regionprops(L, 'centroid'); %STATS = regionprops(BW, properties) measures a set of properties for each connected component (object) in the binary image, BW. The image BW is a logical array; it can have any dimension.
dt = regionprops(L, 'area'); %
cv = regionprops(L, 'perimeter'); %
dim = size(s) %
boundaries = bwboundaries(bw); %
imshow(bw);
figure;imshow(I);
hold on; %
for k=1:dim(1) %
b= boundaries{k}; %
dim = size(b) %
for i=1:dim(1) %
F{k}(1,i) = sqrt ( ( b(i,2) - s(k).Centroid(1) )^2 + ( b(i,1) - s(k).Centroid(2) )^2 ) %
end %
a=max(F{k}); %
b=min(F{k}); %
c=dt(k).Area; %
O=a-b; %
P = c/(4*b^2) %
Q=c/(4*b*(a^2-b^2)^0.5); %
R=(c*3^0.5)/((a+b)^2); %
T =c/(a*b*pi); %
U= (c*( a^2 - b^2 )^0.5) / (2*a^2*b) %
if O < 10 %
text(s(k).Centroid(1)-20,s(k).Centroid(2),'circle') %
elseif (P < 1.05 ) & (P > .95)
text(s(k).Centroid(1)-20,s(k).Centroid(2),'square') %
elseif (T < 1.05 ) & (T > .95 )
text(s(k).Centroid(1)-20,s(k).Centroid(2),'ellipse') %
elseif (U < 1.05 ) & (U > .95 )
text(s(k).Centroid(1)-20,s(k).Centroid(2),'diamond') %
elseif ((Q <1.05) & (Q >.95))
text(s(k).Centroid(1)-20,s(k).Centroid(2),'rectangle') %
elseif (R < 1.05 ) & (R > .95 )
text(s(k).Centroid(1)-20,s(k).Centroid(2),'triangle') %
end
end
What do you mean by 'find the face'? I am able to find face with CV toolbox and draw the rectangle around it. Are you asking me to crop the image leaving the face only and then apply regionprops or something else? Sorry I could not understand it properly.
Somehow you need to find the face and get just the face. I don't have any algorithm or code to suggest to you for doing that. You gave some code above but it doesn't look very robust along. For example how are you going to separate the face pixels from the neck pixels when they are essentially the same color and are next to each other.

Sign in to comment.

Asked:

on 14 Apr 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!