Programs

MATLAB Application in Face Recognition: Code, Description & Syntax

Every time you unlock your mobile phone with your face or pass through your high-tech office surveillance system, an elaborate facial recognition technology is operating in the background. So what is face recognition, and how can you carry out face recognition using MATLAB

Top Machine Learning Courses & AI Courses Online

Facial recognition is the process of identifying human faces through technology. The facial recognition system uses computer vision and Machine Learning techniques to model and classifies facial features extracted from images and videos. Algorithms for face identification extract and map facial features and compare them to a database of known faces to find the best match. 

Face Recognition in Matlab has turned out to be a famous area of research because of its application in image analysis, computer vision, etc. Matlab is one of the outstanding platforms chosen by developers for implementing face recognition applications owing to its built-in features and toolbox support. CSE mini projects

The facial classification process classifies human faces based on gender, age, emotions, and other relevant features using certain applications. The reason why it is dissimilar to face recognition is that it only compares the differences between two different images.

Usually, facial characterization is operated as face recognition technology. But, the facial classification process is done before identifying human faces.  It helps you when working on your MATLAB-based CSE mini projects.

 

  • Facial characteristics that MATLAB applications work on:
  • Mouth Width
  • Eye Eccentricity
  • Head Eccentricity
  • Eyebrow Slant
  • Mouth Openness
  • Mouth Curvature
  • Pupil Size
  • Nose Length
  • Nose Width
  • Eye Size
  • Eye Spacing

These facial characteristics are considered in the human face recognition process in MATLAB.  They help you to map the dimensionalities. Face recognition technology helps legitimate users use the right services by assessing their facial features. Any face recognition outcome is the result of several core processes at the back end. Essentially, face recognition technology is extensively used in all phases of technology to obtain security levels. This technology is used in a myriad of CSE projects for the final year.

Trending Machine Learning Skills

Enrol for the Machine Learning Course from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

 Source

MATLAB in Face Recognition

It is possible to achieve face recognition using MATLAB code. The built-in class and function in MATLAB can be used to detect the face, eyes, nose, and mouth. The object vision.CascadeObjectDetector System of the computer vision system toolbox recognizes objects based on the Viola-Jones face detection algorithm. 

Description of the MATLAB Object Detector

The vision.CascadeObjectDetector makes use of the Viola-Jones algorithm for the identification of faces, eyes, mouth, nose, or the upper body. A custom classifier can be trained by using MATLAB’s Image Labeler and used along with the System object. So how are facial features or the upper body detected in an image? Here are the steps:

  1. The first step involves the creation of the vision.CascadeObjectDetector object and setting its properties.
  2. In this step, the object is invoked with arguments (as if it were behaving like a function).

Read: 15 Interesting MATLAB Project Ideas & Topics For Beginners

Syntax for the Creation of the Object Detector

The syntax used for the creation of the Object Detector is as follows:

  • detector = vision.CascadeObjectDetector
  • detector = vision.CascadeObjectDetector(mode1)
  • Detector = vision.CascadeObjectDetector(Name,Value)
  • detector = vision.CascadeObjectDetector(XMLFILE)

Description of the Syntax

  • detector = vision.CascadeObjectDetector: This syntax is used for the creation of a detector that detects objects using the Viola-Jones algorithm.
  • detector = vision.CascadeObjectDetector(mode1): This syntax is used for the creation of a detector that is configured for detecting objects defined by the input vector – mode1.
  • detector = vision.CascadeObjectDetector(Name,Value): This syntax is used for setting properties by using one or more than one name-value pairs, where each property name is enclosed within quotes. For example: detector = vision.CascadeObjectDetector(‘ClassificationModel’,’UpperBody’)

Check out: Machine Learning Project Ideas

Properties 

Unless otherwise specified, the features of the cascade Object Detector are non-tunable, meaning that after calling the object, their values cannot be altered. Objects get locked when they are invoked, and their unlocking is done by the ‘release’ function.

On the other hand, a tunable property would mean that its value can be changed at any time. So, let us have a look at some of the features before we understand face recognition using MATLAB codes.

  • ClassificationModel: Defined as a character vector, this property is responsible for controlling the type of object to detect. The default configuration of the detector detects faces.
  • MinSize: The size of the smallest recognizable object is denoted as a two-element vector [height width]. Unless a property value is specified, the detector sets it to the image size used for training the classification model.
  • MaxSize: The size of the smallest recognizable object is denoted as a two-element vector [height width]. Unless a property value is specified, the detector sets it to size (I). 
  • ScaleFactor: It has a specified value higher than 1.0001. This property is for incremental scaling of the detection resolution between MinSize and MaxSize.
  • MergeThreshold: It has a specified integer value equal to 4. In case there are multiple detections around a target object, the threshold defines the final detection criteria.
  • UseROI: Specified as false, this property can be set to true for the detection of objects within a rectangular region of interest in the input image.

FYI: Free nlp course!

Syntax for Using the Object Detector

  • bbox = detector(I)
  • bbox = detector(I,roi)

Description of the Syntax

  • bbox = detector(I) returns bbox, an M-by-4 matrix, that defines ‘M’ bounding boxes that contain the detected objects.
  • bbox = detector(I,roi) is used for detecting objects within the rectangular region of interest, specified by roi. 

Input Arguments

  • I — Input image: It is specified as true color or grayscale (RGB).
  • model — Classification model: It is specified as a character vector and describes the object type to be detected. 
  • XMLFILE — Custom classification model: Specified as an XML file, it can be created using OpenCV training functionality or the trainCascadeObjectDetector function.
  • roi — Rectangular region of interest: A four-element vector [x y width height] is used to specify this input argument.

Output Arguments

bbox — Detections: Detections are returned as an M-by-4 element matrix, each row of which contains the four-element vector [x y width height].

Object Functions Common to All System Objects

  • step: For running System Object algorithm
  • release: For releasing system resources 
  • reset: For resetting the internal states of System Object.

MATLAB code for face recognition

In this section, we will see an example of face recognition using MATLAB code.

Face Detection

Source

Source

The step(Detector,I) will return Bounding Box value containing [x,y,Height,Width] of the objects under detection:

Source

Nose Detection

Source

Source

Description:

  • The passing of the argument ‘Nose’ denotes that the object of interest is the nose.
  • The default nose detection syntax is vision.CascadeObjectDetector(‘Nose’)
  • The default parameter values passed to vision.CascadeObjectDetector can be modified based on the input image.
  • The ‘MergeThreshold’ value can be overridden to avoid multiple detections around the target object (as in the image above). 

Eye Detection

Source

Source

Also Read: While loop in MATLAB: Everything You Need to Know

Matlab function for face recognition:

The following Matlab functions help you to accomplish various CSE projects for final year.

  1. Face Matching Function :

EuclideDist = ()

This function equates and computes the trained images’ Euclidian distance from the test images projected or proposed.

  1. Training Images for Face Recognition

function (Recognized_Result_Face_Image) = Face_Recognize_Process (Input_Image, Image_Location)

This function lines up the set of human face images by reforming 2D images into 1D column vectors. 2D matrix (X) is developed by inputting 1D column vectors just like those inputted in rows. 

Practising each function in your CSE projects for final year can offer you a great insight into its practical implementation. 

Various face recognition algorithms:

  1. ConvLSTM (Convolutional Long Short-Term Memory):

It combines a convolutional neural network and long short-term memory designed to retrieve local data. The long short-term memory layers allow for capturing the image sequence variations. So, you can use this algorithm in your final year project for computer science based on an image sequence.

  1. RNNs (Recurrent Neural Networks):

Image classification is performed using dynamic temporal behaviours. It assesses samples even with former inputs for performing exact contexts. Moreover, it considers the preceding frame’s images as contexts.

iii. CNN (Convolutional Neural Networks):

Image classification happens by utilizing go-to neural networks that adapt to various facial patterns

The greatest strength of CNN (Convolutional Neural Network) is to use of temporal frameworks. It, therefore, merges local data with the recurrent neural network. This algorithm captures the transitions among various facial patterns. You can use the CNNs algorithm if you are working on final year projects for computer science that needs to analyze facial patterns’ transition.

CNN applies kernels to each image input chunk, generating a new activation matrix. They process images’ sensitive components by normalization techniques. 

  1. SVMs (Multiclass Support Vector Machines):

This supervised deep learning technique classifies and analyzes the given inputs to interpret images further. It only works with the images caught in a structured manner. This algorithm is used in many final year projects for computer science where in-depth image interpretation is required.

Matlab program for face recognition application using PCA (Principal Component Analysis):

Principal component analysis (PCA) is a statistical process that uses an orthogonal transformation to transform a set of correlated variables’ observations into a set of linearly uncorrelated variables’ values (also called principal components). It is a popular final year project for computer science that teaches several unique fundamentals of Matlab.

Suppose there are n observations with p variables. The number of individual principal components is min(n-1,p).   In this transformation, the foremost principal component shows the greatest possible variance. Every succeeding component has the highest possible variance under the limitation that it is orthogonal to the previous components. The output vectors represent an uncorrelated orthogonal basis set. PCA is sensitive to the relative scaling of the original variables. You can apply these concepts of PCA in one of your suitable mini project topics for CSE 3rd year.

Matlab system testing for face detection:

Follow these steps for Matlab system testing:

  1. Install Matlab version R2012a or higher in your system. Now launch it from the desktop shortcut.
  2. Now, download the source folder.
  3. You now need to check the device ID and mention the device ID number in the source code.
  4. Run the program, after which a GUI will be displayed.
  5. Click on the “Start” button to initialize the camera settings.
  6. Now click on the “Face” button to allow the camera would detect the face. So, your face will be detected and shown on the screen’s right side.
  7. Likewise, you can detect your upper body and eyes by clicking on the corresponding buttons.
  8. Click on the “Stop” button to stop the previous process, after which you can detect the remaining two features.
  9. Click on the “Stop” button after all features are detected.

Practising these steps helps you to easily undertake the coding of one of your mini project topics for CSE 3rd year.

Mouth Detection

Source

Also Read: While loop in MATLAB: Everything You Need to Know

Source

Popular Machine Learning and Artificial Intelligence Blogs

Wrapping Up

While face recognition technology is beneficial for verification of personal identity, it does raise privacy issues. Since the technology uses an individual’s faceprint, it is often regarded as a breach of one’s privacy, safety, and security. Face recognition using MATLAB can be employed in several cases where security is of utmost concern. From airports and offices to smartphones, facial recognition has become an integral component of many systems and organizations.

If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.

What is face recognition?

Face recognition can be used to protect against identity theft, as well as to identify individuals by name. However, given that face recognition is relatively new and is continuously being developed, it's important to understand the basics of face recognition in order to use it effectively. Face recognition refers to the process of determining whether a face image belongs to a known person. The problem of face recognition can be divided into two tasks: 1) Face Detection – locating the face in the image, 2) Face Recognition – identification of the person whose face it is.

What is Matlab?

Matlab is a programming language for numerical calculation. Basically, it is a matrix programming language. It is used a lot in scientific and engineering calculations. Unlike the other programming languages, MATLAB was designed to be a matrix language, one that is suitable for computation on matrices. Matrices are used in a lot of different equations, especially in scientific and engineering calculations. Matlab is a high-level programming language which comes with a large number of functions. It is used to solve mathematical problems, analyze data and create graphs.

What is Viola Jones in Matlab?

The Viola Jones algorithm is used for face detection and facial expression recognition. Viola Jones algorithm is based on Histograms of Oriented Gradients (HOG) that was first introduced by Paul Viola and Michael Jones in 2001. It is used in computer vision, machine learning, and image processing. Viola Jones algorithm provides a complete object detection system and it may be used in pedestrian detection, object detection, or human detection. Viola Jones algorithm consists of a feature extraction step, a clustering step, and an object classification step.

Want to share this article?

Prepare for a Career of the Future

PG DIPLOMA FROM IIIT-B, 100+ HRS OF CLASSROOM LEARNING, 400+ HRS OF ONLINE LEARNING & 360 DEGREES CAREER SUPPORT
Enroll Today

Leave a comment

Your email address will not be published. Required fields are marked *

Our Popular Machine Learning Course

Get Free Consultation

Leave a comment

Your email address will not be published. Required fields are marked *

×
Get Free career counselling from upGrad experts!
Book a session with an industry professional today!
No Thanks
Let's do it
Get Free career counselling from upGrad experts!
Book a Session with an industry professional today!
Let's do it
No Thanks