Professional Documents
Culture Documents
Expt. No. 5
Roll No :- 60
Theory :-
Image processing is the technique to convert an image into digital format and
perform operations on it to get an enhanced image or extract some useful
information from it. A digital image may be defined as a two-dimensional function
f(x,y), where ‘x’ and ‘y’ are spatial coordinates and the amplitude of ‘f’ at any pair
of coordinates is called the intensity of the image at that point. When ‘x,’ ‘y’ and
amplitude values of ‘f’ are all finite discrete quantities, the image is referred to as a
digital image.
Basic image processing commands in MATLAB:
Multiple images can be displayed within one figure using the subplot
function. This function has three parameters within the brackets:
subplot(a,b,c), where the first two parameters specify the number of rows
and columns to divide the figure.
Images are written to the current directory using the imwrite function, which
has the following syntax:
Imwrite(f,”filename”), This command writes image data ‘f’ to the file
specified by ‘filename’ in your current folder.
The imhist function creates a histogram plot by defining n equally spaced
bins, each representing a range of data values, and then calculating the
number of pixels within each range.
Imhist();
Code :-
clc;
clear all;
close all;
img = imread('image.jpg');
imshow(img)
imwrite(img, 'image_1.png');
img = imread('cameraman.tif');
subplot(2,2,1);
imshow(img)
title('Original Image');
subplot(2,2,3);
imhist(img)
title('Historgram');
binaryImg = zeros(256, 256);
for i=1: 256
for j=1: 256
if img(i,j) >= 128
binaryImg(i,j) = 255;
else
binaryImg(i,j) = 0;
Bansilal Ramnath Agarwal Charitable Trust’s
end
end
end
subplot(2,2,2);
imshow(binaryImg)
title('Binary Image');
subplot(2,2,4);
imhist(binaryImg)
title('Historgram');
2. Image Negation
clc;
clear all;
close all;
img = imread('cameraman.tif');
subplot(2,2,1);
imshow(img)
title('Original Image');
subplot(2,2,3);
imhist(img)
title('Historgram');
dim = size(img);
row = dim(1);
col = dim(2);
for i = 1 : row
for j = 1 : row
end
end
subplot(2,2,2);
imshow(new_img)
title('Negative Image');
subplot(2,2,4);
imhist(new_img)
title('Historgram');
Result :-
1]
Bansilal Ramnath Agarwal Charitable Trust’s
2] Image Negation
Conclusion :-
Bansilal Ramnath Agarwal Charitable Trust’s
In this experiment basics of image processing were performed like reading and
writing of image, plotting of image histogram, potting its subplot and creating its
binary and negative image and performing basic operations on it.