EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • 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.

ADVERTISEMENT
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
ADVERTISEMENT
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
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
  • Blog as Guest
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

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

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

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Cyber Monday Reloaded Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW