MATLAB Image Processing

After reading the MATLAB image processing topic, you will able to solve problems on modifying images in MATLAB, and you will also understand how to image resize, image rotate, image display, cropping an image using MATLAB.

MATLAB stores image as a two-dimensional array, i.e. in matrices form. The pixel in the image represents each element of matrices.

How to Read an Image in MATLAB?

We can read an image in matrix form. The MATLAB built-in imread() function used for displaying the data of the image.

General Form:

img = imread('pout.tif');            

where,

  • pout is the name of the image to be open.
  • img is an array which stores image pout.
  • .tif is the image file extension.

Example

Aim (1): To read image in MATLAB.

Program (1):

img = imread('pout.tif');

Output (1):

Display Image

We can also display an image using MATLAB. The MATLAB built-in imshow() function used for displaying the data of the image.

General Form:

imshow(img)

where,

  • img is an array which stores image to be displayed.

Example

Aim (1): To display image in MATLAB.

Program (1):

img = imread('pout.tif');      
imshow(img)                    

Output (1):

Resizing an Image

In MATLAB manually resize of an image, first read the image to be resized and then apply resizing operation on the image.

Example

Aim (1): To resize an image in MATLAB.

Program (1):

img = imread('pout.tif');         
img1=img(1:3:end,1:3:end);        
imshow(img1)                      

Output (1):

where,

  • img is an array which stores the original image.
  • statement img1=img(1:2:end,1:3:end); use to resize an image. Here, 1:2: end describes height range and 1:3: end describes width range.
  • Img1 is an array which stores image after resizing operation.

Rotating an Image

In MATLAB, built-in imrotate() function used for rotation of image. We can rotate an image at any angle in counterclockwise direction.

General Form:

img1 = imrotate(img,ang)

where,

  • img is an array which stores image to be displayed.
  • ang is the angle of counterclockwise rotation in degree.

Example

Aim (1): To rotate an image by 30 degrees in MATLAB.

Program (1):

img = imread('pout.tif');     
img1=imrotate(img,30);        
imshow(img1)                  

Output (1):

Cropping an Image

In MATLAB for cropping of the image, first read the image to be cropped and then apply cropping operation on the image.

General Form:

img1=img(h,w);

where,

  • h is the height range for cropping an image.
  • w is the width range for cropping an image.

Example

Aim (1): To rotate an image by 30 degrees in MATLAB.

Program (1):

img = imread('pout.tif');          
img1=img(100:200,100:150);         
imshow(img1)                       

Output (1):

Leave a Comment

error: Content is protected !!