Open In App

MATLAB – Read images using imread() function

Last Updated : 12 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for technical computing. It was developed by Cleve Molar of the company MathWorks.Inc in the year 1984. It is written in C, C++, Java. It allows matrix manipulations, plotting of functions, implementation of algorithms, and creation of user interfaces. 

In this article, we are going to discuss how to read images using MATLAB.

In-order to read images we are going to use the imread() function in MATLAB. The imread() function reads images from the graphics files.

Syntax:

A = imread(filename)

It simply read the image and stores it in A.

A = imread(filename,fmt)

Reads image in grayscale or color from the specified file.if image is not present in current directory then please provide the full path of image.

A = imread(Name,Value)

It peruses the predefined picture or pictures from a multi-picture record. This grammar applies just to GIF, PGM, PM, PPM, CUR, ICO, TIF, SVS, and HDF4 documents. You should indicate a filename information, and you can alternatively determine fmt.

Example 1:

Below is a program in which we read a color image using imread() function and store it in A (the imread() function restores the picture information in cluster A) and then we display the image using imshow() function. 

C++




% reading image
A = imread('g4g.jpg');
 
% displaying image
imshow(A);


Output:

 

Example 2:

Here is another example to read an image in MATLAB.

C++




% reading image
A = imread('g4g.jpg');
 
% displaying image
imshow(A);


Output:

Note: In the event, if the image is grayscale then, A will be a two-dimensional (M-by-N) exhibit, or else A will be a three-dimensional (M-by-N-by-3) exhibit. The class of the returned cluster relies upon the information type utilized by the record design.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads