Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
How to Detect Shapes in Images in Python using OpenCV?
Next article icon

How To Detect Face in Image Processing Using MATLAB?

Last Updated : 05 Oct, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

MATLAB  is a programming platform that is mainly used by engineers and scientists to analyze and design systems. Image processing is a process to perform some operations on an image to get an enhanced image or to extract some useful information from it. Each picture is stored as an array and each pixel is an element of the array. 

Face Detection:

Face detection also called facial detection is an artificial intelligence (AI) based computer technology used to find and identify human faces in digital images.  Face Detection is widely used in projects and software. it can be called a subset of image processing. MATLAB provides the interface to practice and learn image processing skills in an effective manner.

Example 1:

Matlab
% MATLAB program for GeeksforGeeks  % logo detection X=imread("monochrome1.png");  Y=imread("GeeksforGeeks.svg.png");  subplot(2,1,1)    imshow(X);    subplot(2,1,2)    imshow(Y); 

Output:

 

Explanation:

  1. HERE "imread" is the command to MATLAB to take input of image address on which we are working. "imread" takes image address which can be taken from the image which is present in MATLAB drive. 
  2. "subplot" is the command we used to add multiple images in a single frame. subplot(2,1,1) works as (row=2, column=1, position=1) .  
  3. This will work as a matrix formation of 2x1 matrix 2 rows, 1 column, and the third number (2,1,1) shows the position of the image and as result, the image is considered to be an element of the matrix. 
  4. The "imshow" command is used to get the desired result. the interface will give you desired output on compiling it.   "imshow" is the fundamental image display function in MATLAB, optimizing figure, axes, and image object property settings for image display.
     

image processing is not limited to a certain scope, it has many uses and features such as changing image color, extracting color, making filters, etc. Any image comprises RGB values which can be extracted from the image to make it different in appearance.

filters are like matrix as same as the size of our image suppose " image1 is matrix A" and "filter is matrix B" these both matrix gets multiplied and gives a new filtered image [A x B = C]. 

Example 2:

Matlab
% MATLAB code for changing image color  % gray %changing image color to gray    X=imread("monochrome1.png");     Y=imread("GeeksforGeeks.svg.png");    subplot(2,2,1)    imshow(X);    subplot(2,2,2)     z=im2gray(Y);   imshow(z);     subplot(2,2,3)   imshow(Y);   subplot(2,2,4)   G=Y(:,:,2);   imshow(G); 

Output:

 

Explanation:

  1. Adding images, subplot them in the same frame adding image address will remain same in all cases.  
  2. Here new terms are "im2gray" (image to gray ) it changes the color image in gray color. im2gray(RGB) converts the true color image RGB to the grayscale intensity image I. Grayscale inputs to im2gray are returned unchanged. For any device binary scale image is easy and more compatible to use in their functioning, This is one of the advantages.
  3.  "G=Y(:,:,2)" stands for green color and the code shows how we can extract the green color components from an image. 

Now, Facial detection has now become an important feature in today’s technological development there are many advantages of face detection (image processing).

Example 3: 

Matlab
% MATLAB code for face detection     Detector=vision.CascadeObjectDetector('EyePairBig');            Detector.MinSize=[11 45];                                             Detector.MergeThreshold=16;            DDetector=vision.CascadeObjectDetector('Mouth');                                              DDetector.MinSize=[15 25];                                                                                 DDetector.MergeThreshold=16;                    EDetector=vision.CascadeObjectDetector('Nose');                  EDetector.MinSize=[15 18];                                                     EDetector.MergeThreshold=16;       CDetector=vision.CascadeObjectDetector('EyePairSmall');                    CDetector.MinSize=[5 22];                                                                                      CDetector.MergeThreshold=16;      % Read an images   I=imread("face.jpg");       J=imread("face.jpg");     K=imread("face.jpg");    L=imread("face.jpg");    bbox=step(Detector,I);         box=step(DDetector,J);              cbox=step(EDetector,K);         dbox=step(CDetector,L);       % Functions for face fecefeatures detection   FaceFeature=insertObjectAnnotation(I,'rectangle',bbox,'Detected');       FaceFeature2=insertObjectAnnotation(J,'rectangle',box,'Detected');    FaceFeature3=insertObjectAnnotation(K,'rectangle',cbox,'Detected');     FaceFeature4=insertObjectAnnotation(L,'rectangle',dbox,'Detected');      figure;     % Plot    subplot(2,2,1);      % For showing facefeatures   imshow(FaceFeature);                                                        title('EYES detected');                     subplot(2,2,2);                                imshow(FaceFeature2);                                             title('MOUTH detected');                   subplot(2,2,3);                   imshow(FaceFeature3);              title('NOSE detected');      subplot(2,2,4);                      imshow(FaceFeature4);             title('EYE SMALL detected'); 

Output:

 

Explanation:

  • It follows viola jones's algorithm and vision.CascadeObjectDetector is act as a function or command. all 4 features can be easily detected from this code like mouth, nose, etc. as four features will display at the same time eventually code length increases but the concept for all 4 phases is the same. This detector is capable of detecting a variety of objects, including faces and a person's upper body.  
  • MinSize Size of the smallest object to detect Specify the size of the smallest object to detect, in pixels as a two-element vector, [height width]. Use this property to reduce computation time when the minimum object size is known.  Here Minsize [11 45] height =11 and width = 45 prior to processing the image. Detector.MinSize=[X Y];  denotes coordinates as we get desired output from these. 
  •  insertObjectAnnotation is again used as a command that we want the image in the desired box.  A subplot has the same role to add multiple images in same frame. Insert annotation in image or video stream.   This function inserts labels and corresponding circles or rectangles into an image or video.                     insertObjectAnnotation(I,'rectangle',box,'Detected');  shows image 'I' we want it in rectangular box as it detects. 
  • MergeThreshold Threshold for merging detections Specify a threshold value as a scalar integer. This property defines the minimum number of colocated detections needed to declare a final detection. MergeThreshold 16 scalar int here is "16" . 
  • Box all other just used as variable store the command to detect image.  In last phase of code we just written the basic steps of subplot and imshow to get the desired result. Subplot will work same to gather images position wise. title we add in last phase determines title one wants to add with the output image or result. 

Next Article
How to Detect Shapes in Images in Python using OpenCV?
author
dhruvdosi2003
Improve
Article Tags :
  • MATLAB

Similar Reads

  • Introduction to Object Detection Using Image Processing
    Object detection is a crucial task in computer vision that involves identifying and locating objects within an image or video. This task is fundamental for various applications, including autonomous driving, video surveillance, and medical imaging. This article delves into the techniques and methodo
    7 min read
  • Adaptive Histogram Equalization in Image Processing Using MATLAB
    Histogram Equalization is a mathematical technique to widen the dynamic range of the histogram. Sometimes the histogram is spanned over a short range, by equalization the span of the histogram is widened. In digital image processing, the contrast of an image is enhanced using this very technique.  A
    3 min read
  • Digital Image Processing Algorithms using MATLAB
    Like it is said, "One picture is worth more than ten thousand words "A digital image is composed of thousands and thousands of pixels. An image could also be defined as a two-dimensional function, f(x, y), where x and y are spatial (plane) coordinates and therefore the amplitude of f at any pair of
    8 min read
  • How to Detect Shapes in Images in Python using OpenCV?
    Prerequisites: OpenCV OpenCV is an open source library used mainly for processing images and videos to identify shapes, objects, text etc. It is mostly used with python. In this article we are going to see how to detect shapes in image. For this we need cv2.findContours() function of OpenCV, and als
    3 min read
  • How to Convert RGB Image to Binary Image Using MATLAB?
    An Image, by definition, is essentially a visual representation of something  that depicts or records visual perception. Images are classified in one of the three types.  Binary ImagesGrayscale ImagesColor ImagesBinary Images: This is the most basic type of image that exists. The only permissible pi
    3 min read
  • How to Convert RGB Image to YIQ Image using MATLAB?
    Image Processing in MATLAB use functions from the Image Processing Toolbox. This toolbox generally represents colors as RGB numeric values. Different models also exist for representing colors numerically. The official term for these models is "color spaces" and is coined from the definition of a vec
    2 min read
  • MATLAB - Image Edge Detection using Sobel Operator from Scratch
    Sobel Operator: It is a discrete differentiation gradient-based operator. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Sobel operator produces either the normal to a vector or the corresponding gradient vector. It uses tw
    3 min read
  • How to Count the Number of Circles in Given Digital Image Using MATLAB?
    In image processing, connected component analysis is the technique to count and inspect the segments automatically. Let suppose, we have an image consisting of small circles. There are hundreds of circles in the image. We need to count the number of circles. It will take a lot of time if we count ma
    3 min read
  • How to Remove Noise from Digital Image in Frequency Domain Using MATLAB?
    Noise is defined as aberrant pixels. In other words, noise is made up of pixels not correctly representing the color or exposure of the scene. In this article, we will how to remove noise from the digital images in the frequency domain. There are two types of Noise sources Image acquisitionImage tra
    5 min read
  • How to Blur Faces in Images using OpenCV in Python?
    Prerequisite: OpenCV OpenCV is a huge open-source library for computer vision, machine learning, and image processing.  It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a highly optim
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences