EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab Imread
 

Matlab Imread

Updated March 8, 2023

Matlab Imread

 

 

Introduction to Matlab Imread

Imread function is used in MATLAB to read images or color scales from graphic files, which are in the formats such as ’bmp,’ ‘cur,’ ‘gif,’ ‘jpg,’ ‘hdf,’ ‘ico’ etc. If no format is mentioned in the syntax of the Imread function, it infers the format from the contents of the file.Imread function only “reads” an image into a variable initiated by us; in order to display the image on our work, we need to use the ‘imshow’ function in conjunction with the imread function.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

The graphic file from which we read the image can be in a MATLAB directory or a file saved by us.

Below is the table showing some of the formats supported by the Imread function:

Format Description Variants
1. ‘bmp’ Bitmap 1, 4, 8, 16, 32-bit uncompressed image
2.‘cur’ Cursor resources 1, 4, 8-bit uncompressed image
3.‘gif’ Graphics Interchange Format 1 to an 8-bit image
4.‘hdf’ Hierarchal Data Format 8-bit raster, with or without colormap
5.‘ico’ Icon resources 1, 4, 8-bit uncompressed image

Let us now understand the syntax of the Imread function in MATLAB:

Syntax

  1. I = imread (file)
  2. I = imread (file, fmt)

Description:

  1. I = imread (file) will read the image specified by the argument ‘file.’ Since we have not passed any format argument in this syntax, it will infer the format from the file’s contents. In case the file has multiple images, imread will read only the 1st image. If we want imread to read an image other than the first image, we will have to pass the number of the image as an argument.
  2. I = imread (file, fmt) will read a color image or a greyscale present in the file passed as an argument. In this syntax, we have also specified the format of our file.

Examples of Matlab Imread

Let us now understand the code to read an image from a file in MATLAB using the ‘imread (file) function’ with the help of various examples.

Example #1

In this example, we will read an image from the ‘moon.tif’ file, which is present in MATLAB’s directory. Below are the steps to be followed:

  1. Call the imread function to read the image.
  2. Call the imshow function to display the image read in our workspace

Code:

I = imread (‘moon.tif’)

[Using the imread function to read the image of the moon]

imshow (I)

[Passing the image read in the above step to imshow function. This will display the image in our workspace]

Input:

I = imread ('moon.tif')
imshow (I)

Output:

Matlab Imread output 1

As we can see in the output, we have obtained an image of the moon, which we read from MATLAB’s file.

Example #2

In this example, we will read an image from the ‘kids.tif’ file present in MATLAB’s directory. Below are the steps to be followed:

  1. Call the imread function to read the image.
  2. Call the imshow function to display the image read in our workspace

Code:

I = imread (‘kids.tif’)

[Using the imread function to read the image of the kids]

imshow (I)

[Passing the image read in the above step to imshow function. This will display the image in our workspace]

Input:

I = imread ('kids.tif')
imshow (I)

Output:

Matlab Imread output 2

As we can see in the output, we have obtained an image of the kids, which we read from MATLAB’s file.

In the above 2 examples, we read the images present in the first position in our input files. Next, we will learn how to read a particular image if the file has multiple images.

Example #3

In this example, we will read the 3rd image from the ‘corn.tif’ file, which is present in MATLAB’s directory. Below are the steps to be followed:

  1. Call the imread function and pass ‘3’ as 2nd argument to read the third image.
  2. Call the imshow function to display the image read in our workspace

Code:

I = imread (‘corn.tif’, 3)

[Using the imread function to read the image of the corns. The second argument passed represents the position of the image which we want to read in the file]

imshow (I)

[Passing the image read in the above step to imshow function. This will display the image in our workspace]

Input:

I = imread ('corn.tif', 3)
imshow (I)

Output:

output 3

As we can see in the output, we have obtained an image present at position 3 in the file ‘corns.tif,’ which was read by us from MATLAB’s directory.

In all the above examples, we have read the image from the ‘tif’ file. Next, we will learn how to read an image from the ‘png’ format.

Example #4

In this example, we will read an image from the ‘peppers.png’ file, which is present in the MATLAB directory. Below are the steps to be followed:

  1. Call the imread function to read the image.
  2. Call the imshow function to display the image read in our workspace

Code:

I = imread (‘peppers.png’)

[Using the imread function to read the image from png file]

imshow (I)

[Passing the image read in the above step to imshow function. This will display the image in our workspace]

Input:

I = imread ('peppers.png')
imshow (I)

Output:

output 4

As we can see in the output, we have obtained an image of the peppers, which we read from a png file.

Conclusion

  1. Imread is used in MATLAB to read an image from a graphic file. MATLAB supports various formats from which we can read images
  2. Imread function can also be used to read images from multi-image files

Recommended Article

This is a guide to Matlab Imread. Here we discuss the various Examples of Matlab Imread along with the codes and outputs. You may also have a look at the following articles to learn more –

  1. Matlab Syms
  2. Magnitude Matlab
  3. Convolution Matlab
  4. Bandpass Filter Matlab

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW