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
  • Software Engineering Tutorial
  • Software Development Life Cycle
  • Waterfall Model
  • Software Requirements
  • Software Measurement and Metrics
  • Software Design Process
  • System configuration management
  • Software Maintenance
  • Software Development Tutorial
  • Software Testing Tutorial
  • Product Management Tutorial
  • Project Management Tutorial
  • Agile Methodology
  • Selenium Basics
Open In App
Next Article:
Python | Morphological Operations in Image Processing (Opening) | Set-1
Next article icon

Image Processing in MATLAB | Fundamental Operations

Last Updated : 06 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

1. Reading Images 

Images are read into the MATLAB Environment using imread() function which takes filename with applicable extension as the argument 

For Example: 

>> I=imread('nature.jpg');

This will read JPEG image ‘nature’ into the image array. 

Note: The semicolon(;) at the end of command line is used to suppress the output in MATLAB.If ‘;’ is not used at the end, it will show the output of the specified operation. 

2.Displaying Images 

imshow() function is used to display images in MATLAB. The basic syntax of imshow() is 

imshow(f, G); 

Here f is image matrix and G is number of intensity level used to display the image. The second Argument in the above syntax is optional. If G is omitted its value defaults to 256 levels. 

When we use the syntax 

imshow(f, [Low, High]); 

It displays all value less than or equal to ‘Low’ as black and all values greater than or equal to ‘High’ as white. The values between ‘Low’ and ‘High’ are displayed as the intermediate intensity value using the default number of levels. 

Examples: 

Showing Grayscale Images 

>> imshow(f);

This will display the grayscale image f. 

Also, we can write  

>> imshow(f, [90, 180]);

It will display all value less than or equal to 90 as black and all values greater than or equal to 180 as white. The values between 90 and 180 are displayed as the intermediate intensity value using the default number of levels. 

Showing Binary images  

>> imshow(BW);

It displays the binary image BW. It displays pixels with the value 0 (zero) as black and pixels with the value 1 as white. 

Showing RGB images  

>> imshow(f);

It displays the RGB image f. 

3. Writing images to disk 

Images are written to disk using imwrite() function. The basic syntax of imwrite() is 

imwrite(f, ‘filename’); 

Here f is our image and filename is the name of file including a recognized file format extension. Alternatively, we can also specify desired format explicitly with a third argument. 

For example 

>> imwrite(f, 'nature.jpg');

Alternatively, we can write it as, 

>> imwrite(f, 'nature', 'jpg');

The above commands write image f to a filename nature with extension jpg. 

Note: The imwrite() function have some optional parameters too, depending upon file format. 

For example:  

>> imwrite(f, 'filename', 'quality', q); 

The above syntax is applicable for only JPEG images. Here q is an integer and can take value between 0 to 100. Lower the value of q higher the degradation due to JPEG compression. 

Some Other Important functions 

i.) imfinfo 

It displays the details of an image file 

Example: 

>> imfinfo nature.jpg;

Output:  

          Filename: 'nature.jpg'         FileModDate: '23-Jun-2016 09:57:04'            FileSize: 238290              Format: 'jpg'       FormatVersion: ''               Width: 1920              Height: 1200            BitDepth: 24           ColorType: 'truecolor'     FormatSignature: ''     NumberOfSamples: 3        CodingMethod: 'Huffman'       CodingProcess: 'Sequential'             Comment: {'CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), quality = 92?'} 

ii.) size() 
size() function take image matrix as an argument and give the row and column dimension of an image f. This function is used to determine the size of an image automatically. 

Example :  

>> size(f)

Output :  

ans =   1920 1200

Here 1920 is the number of rows and 1200 is the number of columns in image f. 

Note: As we know RGB images are represented using 3-D matrix in MATLAB. So, if f is a RGB image the above function will produce output as 

ans =   1920 1200 3

iii.) whos f 

This function will show additional detail about image matrix f. 

Example :  

whos f

Output :  

 Name        Size                Bytes    Class    Attributes   f         300x400x3            360000   uint8   

 



Next Article
Python | Morphological Operations in Image Processing (Opening) | Set-1

I

ihritik
Improve
Article Tags :
  • Software Engineering
  • Image-Processing

Similar Reads

  • Python | Morphological Operations in Image Processing (Gradient) | Set-3
    In the previous articles, the Opening operation and the Closing operations were specified. In this article, another morphological operation is elaborated that is Gradient. It is used for generating the outline of the image. There are two types of gradients, internal and external gradient. The intern
    2 min read
  • Image Edge Detection Operators in Digital Image Processing
    In digital image processing edges are places where the brightness or color in an image changes a lot. These changes usually happen at borders of objects. Detecting edges helps us understand the shape, size and location of different parts in an image. Edge detection is used to recognize patterns, und
    5 min read
  • Image Processing In Java - Get and Set Pixels
    Prerequisite - Image Processing in Java - Read and Write In this set, we will learn about the pixels of images, how we can get pixel values of an image and how to set pixel values in an image using Java programming language. Pixels are the smallest unit of an image which consists of four components
    3 min read
  • Negative of an image in MATLAB
    The negative of an image is achieved by replacing the intensity 'i' in the original image by 'i-1', i.e. the darkest pixels will become the brightest and the brightest pixels will become the darkest. Image negative is produced by subtracting each pixel from the maximum intensity value. For example i
    2 min read
  • Python | Morphological Operations in Image Processing (Opening) | Set-1
    Morphological operations are used to extract image components that are useful in the representation and description of region shape. Morphological operations are some basic tasks dependent on the picture shape. It is typically performed on binary images. It needs two data sources, one is the input i
    3 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
  • Extract bit planes from an Image in Matlab
    Image is basically combination of individual pixel (dots) information. When we write that image is of 620 X 480 size, it means that image has 620 pixel in horizontal direction and 480 pixel in vertical direction. So, altogether there is 620 X 480 pixels and each pixels contains some information abou
    3 min read
  • Create Mirror Image using MATLAB
    Prerequisite: Image representation in MATLAB In MATLAB, Images are stored in matrices, in which each element of the matrix corresponds to a single discrete pixel of the image. We can get the mirror image of the given image if we reverse the order of the pixels (elements of the matrix) in each row. C
    2 min read
  • Arithmetic operations using OpenCV | Python
    Prerequisite: Arithmetic Operations on Images using OpenCV | Basics We can perform different Arithmetic operations on images e.g. Addition, Subtraction, etc. This is possible because images are actually stored as arrays (3 Dimensional for RGB images and 1 dimensional for the grayscale images). Impor
    2 min read
  • Top Python libraries for image processing
    Python has become popular in various tech fields and image processing is one of them. This is all because of a vast collection of libraries that can provide a wide range of tools and functionalities for manipulating, analyzing, and enhancing images. Whether someone is a developer working on image ap
    9 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