How to read and display an image using matlab?
How to read and display an image using matlab
way -1:
The simplest way to read an image is to store the image in the current directory (workspace) of Matlab and then use the function imread as follows:
img = imread('baby.jpg'); %% where baby.jpg is the name of the image
%% the image data has been stored in the variable 'img'
way-2:
Alternatively if the image is in a different directory one can use the imread function by specifying the total path of the image
for example:
img= imread('F:\matlab\baby.jpg'); %% reads from the folder matlab
Displaying an image
The command to display images is as follows:
imshow(img); %% will show the image
The problem here would be that the image would replace the current open image (if any).
For this it is better to use :
figure, imshow(img); %% will open the image in a new window
here figure is taken the default value of current number of figure. if you want you can also assign the number as follows
figure(2), imshow(img);
No comments