Easy Way to do Digital Image Processing using MatLab - SeekNLearn.in

Display Greyscale, RGB, Binary and Index Images and Store them in different formats.

MATLAB code to display different grayscale,rgb,binary and indexed images

We can display different types of images like grayscale,colour,binary image and index images in MATLAB through the inbuilt function “imshow”. At first, we should clear the command window,workspace containing variables and the figure window if it was left open previously.

By using the function impixelinfo,we can determine the pixel information by clicking anywhere on the displayed image.

Matlab code:

warning off;
clc;
clear all;
close all;
%%  Displaying Image
I1=imread('image.jpg');    	%Grayscale image
I2=imread('colourimage.jpg'); 	%colour image
I3=imread('binaryimage.jpg'); 	%binary image
[I4,map]=imread('trees.tif'); 	%index image


figure();
imshow(I1);title('Gray Image');impixelinfo;
figure();
imshow(I2);title('Colour Image');impixelinfo;
figure();
imshow(I3);title('Binary Image');impixelinfo;
figure();
imshow(I4,map);title('Indexed Image');impixelinfo;

MATLAB code to store the images in hard drive using different formats

We can  store the image by using the function,“imwrite” in a specified folder using different formats too.The format which we want to store the original image should be specified and the original format in the function. At first, we should clear the command window,workspace containing variables and the figure window if it was left open previously. The function can be written as- imwrite(original image,specified format,original format)

Matlab code:

%% Image Storing
warning off;
clc;
clear all;
close all;
a=imread('cameraman.tif');
imwrite(a,'cameraman_converted.jpg','tiff');

MATLAB code to determine the size,maximum and minimum value of a grayscale image

The dimensions of a grayscale image can be determined by using some of the inbuilt functions in matlab.

Maximum value of a grayscale image can be known by  using the function max(max(original image)).It is very important to note that the word ‘max’ is to be written two times for a grayscale image.

Minimum value of a grayscale image can be known by  using the function min(min(original image)).It is very important to note that the word ‘min’ is to be written two times for a grayscale image.

Size of a grayscale image can be known by  using the function size(original image). 

Matlab code:

warning off;
clc;
clear all;
close all;
 
%% Reading Images

I1=imread('cameraman.tif');    	%Grayscale image

 %% Dimension of images
M1=max(max(I1));
m1=min(min(I1));
s1=size(I1);
fprintf('\nMaximum Value of image 1 is %d\n',M1)
fprintf('Minimum Value of image 1 is %d\n',m1)
fprintf('Size of image 1 is %d %d\n',s1)