Total Pageviews

Translate

October 5, 2016

Facial Feature Detection Using MATLAB...

by 4hathacker  |  in Image Processing at  5:34 PM

Hello Everyone...!!!

In the previous articles, I have discussed about object detection and counting. And now we are ready to go through its very special and popular case, Face Detection. It refers to the psychological process by which humans locate and attend to faces in a visual scene. For us, its an everyday activity.



In context of computer technology, face detection is a very vast field in which a machine learns how to detect a face and there are numerous algorithms for detecting and recognizing faces. In the present article, face detection and recognition has applications in photography, security systems, marketing, traffic control system, etc.

Face detection or recognition algorithms contain steps to detect face, normalize the image, extract features and match the face with a database. Face is a bio-metric feature. A feature consists of salient information which is easily describable, and may be used to distinguish objects. The most important facial features are the form of the face, the distance between the eyes, the length of the nose, and the width of the mouth. These features for detection by a machine needs a large database and training set. We can think of it as a new born infant who starts learning with the very first day of opening of eyes and gradually came to know of his father, mother or stranger. 



Using MATLAB, you do not need to create our own training sets, until or unless you are involved in a very high level of research work. MATLAB is provided with a vision.CascadeObjectDetector() with a special feature detection capability for face detection and recognition. It is based on Viola Jones Algorithm. It does image split up into search windows which then are entered into classificator cascade. Detector (cascade and search window) is scaled incrementally. Detection results are separated into disjoint subsets.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% Name: Nitin Sharma 
%%%% Code: Facial_Feature_Detection
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I = imread('faces_india2.jpg'); %% Load a test image

FaceDetector = vision.CascadeObjectDetector(); %% feature detector object creation

BB = step(FaceDetector, I);%% Using Face Detector object on test image
%%% This returns Bounding Box values which comprises of [x,y,Height,Width]
%%% of faces to be detected. 

B = insertObjectAnnotation(I, 'rectangle', BB, 'Face'); %% Boxing Faces

figure, imshow(B), title('Detected Faces'); %% Showing Detected Faces in test image 

%%% Displaying Number of Faces
num = size(BB,1);
str_num = num2str(num);
str = strcat('Number of detected faces are: ', str_num);
disp(str);

%%% Cropping All detected faces and saving them in a new
%%% folder for further analysis. It involves a sort of file
%%% handling.
for i = 1:size(BB,1)
 J = imcrop(I,BB(i,:));
   baseFileName = sprintf('faces_%d.jpg', i);
   fullFileName = fullfile('E:\New_subfaces', baseFileName);
   imwrite(J,fullFileName,'jpg');
   figure(3),subplot(4,4,i);imshow(J);   
end


P = imread('E:\New_subfaces\faces_9.jpg');
MouthDetector = vision.CascadeObjectDetector('Mouth','MergeThreshold',16);

%%% Use the same for Nose Detector except put 'Nose' instead of 'Mouth' 
%%% in the arguments for Nose Detection. And for Eyes Detection, use only
%%% single argument 'EyePairBig' in vision.CascadeObjectDetector.

BB = step(MouthDetector, P);
B_Mouth = insertObjectAnnotation(P, 'rectangle', BB_Mouth, 'Mouth'); 
figure, imshow(B_Mouth), title('Detected Mouth');


The source code for image detection provided above is easy to understand with the comments provided. I also have stored the result of analysis using file handling with MATLAB which is depicted in the source code. The test image shown above is one of the high definition wallpapers consists of Indian Cricket Team. The code separates the face of individual player and store the result in a specified folder. Then, using one of the facial result obtained, mouth detection is done. Similarly, this can be elaborated for further feature detection and analysis. 




If you find this article interesting, go, build and run your own code for classificators. One important thing I found at Mathworks File Exchange can be helpful for you.

0 comments:

Like Our Facebook Page

Nitin Sharma's DEV Profile
Proudly Designed by 4hathacker.