Face Detection on Image using Matlab

Images processing has always been an active field of research. There are scope of improvement, innovation, development and modification in image processing. As a result the field is ever expanding, full of challenges and excitements. Usually students start image processing with fundamentals of image processing. It includes related mathematical background, popular algorithms, their implementations and applications. Eventually they start working on projects. One of the most common image processing project is Face Detection. In this article, we are going to explain how to perform Face Detection in Still Picture using MATLAB.

Are you interested in research? You can apply for Research Scholarship from here.

Top Research Scholarships

What does this Article Cover?

This article explains the implementation process of face detection in still picture using MATLAB. Along with explanation, it includes the MATLAB code. Basically it is one of the best resource on the web for beginners who want hands on project on face detection. This article covers:

  • Step by step implementation process
  • The code (Copyright free)

The step by step implementation process explains MATLAB functions used in the code. It makes it easier to understand the process of Face Detection on Image using Matlab. Along with that it describes the roles of those function in the code. The code has been provided here so that you can copy the code and save your time.

Do you want to study Engineering? Here are top 7 reasons you should study Engineering

Why Study Engineering?

Implementation of Face Detection in Still Picture using MATLAB

It is wise to start with the basics. Generally speaking, the most basic version of face detection is Face Detection in Still Picture. In general it is always beneficial to start with the basics because learners get the scope of developing a solid foundation. If you are working with face detection, I recommend you to understand the basics of face detection in still pictures first.

Keep things Organized

In order to keep things organized, create a folder in your computer for this project. Save all of the codes, images and files in of this project in this folder. Remember, eventually you have to take care of much complicated projects. If you do not keep things organized, you have to do over these basic things every time some new project shows up. However, it is not mandatory.

Collecting the Image

We are going to perform Face Detection on Image using Matlab. That means we need an image first. The first task is to download an image that has the frontal face. Then save the image in the folder where we are organizing everything.

Step by Step Implementation

Once we have the image, we are ready to start writing the code. I am going to explain the code line by line. Hopefully it will make it easier to understand.

  1. First read the image using ‘imread()’ function and store it in a variable
  2. Then read the width and height of the image using ‘size()’ function. We need to know the size of the image to resize it. If the image is too large, it will take longer to detect the face. However, reducing the size of the image does not impact the detection accuracy significantly.
  3. Once the size is detected, we are going to initiate an ‘if’ condition.
  4. If the width of the image is more than 320 pixels, then we will resize it to 320 pixel width. We use ‘imresize()’ function to resize images. We will not touch the height so that the width and height ratio is maintained by the function.
  5. Now we can use ‘vision.CascadeObjectDetector’, a built-in pre-trained object detection of MATLAB, to detect the face. First of all, we need to create an instance of this object
  6. Then using ‘step()’ function, we have to assign the image to the object detector. After doing it, the ‘step()’ function will return the location of the face
  7. As we have the location of the face on the image now, we can simply draw a rectangle on that location using ‘insertShape()’ function
  8. And finally we can show the image with detected face

Using this simple 8 steps, we can detect face on images using MATLAB.

The Code

The code to detect faces on image has is provided below. The author has tried to keep the code as clean as possible. It is easy to understand and will help the learners grasp the process of detecting faces from images using MATLAB faster. Here is the code to detect faces on image using MATLAB:

%loading the video
the_Image      = imread('nzfaruqui.jpg');
[width, height] = size(the_Image);

if width>320
the_Image = imresize(the_Image,[320 NaN]);
end

% Create a cascade detector object.
faceDetector = vision.CascadeObjectDetector();

%finding the bounding box that encloses the face on video frame
face_Location = step(faceDetector, the_Image);

% Draw the returned bounding box around the detected face.
the_Image = insertShape(the_Image, 'Rectangle', face_Location);
figure; 
imshow(the_Image); 
title('Detected face');

This code has been sponsored by AdmissionScholarships.com. You are free to copy the code, modify it and use it the way you need to perform Face Detection on Image using Matlab. If you need implementation related help, you can watch the following YouTube video:

Face Detection on Image using Matlab
Author:
Nuruzzaman Faruqui
He is a researcher and author. He is a full-time faculty member of Department of Computer Science and Engineering of City University. He teaches Image Processing and Machine Learning.

We are committed to help students to manage financial aids and scholarships for their education. However, our effort alone is not enough. You should build and strengthen your research profile to increase the chance of getting a scholarship. We are always here to help you to find the top scholarships of the world.

Top Scholarship in United States
Top Scholarship in United States

Do you want to study in United States? Is the education cost stopping you? If you are meritorious you have nothing to worry about. Scholarships and financial aids are waiting for you to finance your study in United States (US).

Top Scholarship in Canada

Study in Canada? Definitely a good choice. Top rank universities, amazing environment and job opportunities – everything is in Canada. And there are lots of scholarships to study in Canada.