DIGITAL IMAGE PROCESSING TUTORIAL PART 1 : HOW TO READ IMAGE

In this tutorial blog i will show you how to read an image in Matlab. The procedure is very simple. The persons who have never used Matlab, i will request them to see my blog post on Basic Matlab tutorial or any other tutorial on the same topic from different authors.

 

I prefer to write all my codes in the “m file” of Matlab. See the pictures below to show you how to make an “m file”

FIG 1 : CLICK HERE TO CREATE “m FILE”

 

Fig 2: save the file with a valid file name

 

Fig 3: Write the codes in the “m File”

 

THE CODE TO READ IMAGE AND DISPLAY IT.

% Code 1. read image
rgb1=imread('paper flower.jpg');
figure, imshow(rgb1)

Any statement written with “%” symbol are commented out by Matlab. These are not complied . They are used to explain the steps taking place for the user.

“paper flower.jpg” is the name of my image which is present in my current directory. Change it to the name of your own picture.

Fig 4: run the code

 

” imshow( ) ” is used to display the image.

Even if the image is grayscale image , “imread()” function is smart enough to understand that.

The image is read as a matrix. Thats why i have written

rgb1=imread('paper flower.jpg');

where “rgb1” is the matrix on which the image data has been saved. You can give any name to the variable but remember:

1.Donot start variable name with number

2.Donot give space in between the name. Underscore is allowed but not space. Eg. “my image is rgb” , this variable name is NOT VALID.

but, “my_name_is_rgb” is a valid name.

Try to give such type of variable name which are relevant to the operation you are performing.

In my next blog i will show you how can you read an index image. Its little different from the normal method.

As a reference i will encourage you to study  regarding what is RGB image , Grayscale image and Index image.

Almost all my blog will deal with RGB and/or Grayscale image still its important that you know what is an “indexed image”.

 

Thank you for reading.