Lab 3 PDF
Lab 3 PDF
Date: / /2013
AIM:
To read an image, plot its histogram then do histogram equalization and
histogram specification. Comment in the result. (With and Without using
inbuilt functions)
img = imread('cameraman.tif');
subplot(2,2,1); imshow(img); title('Original Image');
subplot(2,2,2); imhist(img);
clc;
clear all;
close all;
img = imread('cameraman.tif');
subplot(2,3,1)
imshow(img);
title('Original Image');
[r,c]=size(img);
for k=0:255
count=0;
for i=1:r
for j=1:c
if (img(i,j)==k)
count=count+1;
end
N(1,k+1)=count;
end
end
end
x=0:1:255;
subplot(2,3,2)
stem(x,N);
title('Histogram of original image');
s=zeros(r,c);
for L=1:256
for i=1:r
for j=1:c
if img(i,j)==L-6
for k=1:L
s(i,j)=s(i,j)+(N(k)/(r*c));
end
s(i,j)=255*s(i,j);
end
end
end
end
subplot(2,3,4)
imshow(s,[]);
title('equalized image');
x=0:1:255;
subplot(2,3,5)
stem(x,s(x+1));
title('histogram of equalized image');
eq=histeq(img);
subplot(2,3,6)
imhist(eq,64)
title('using inbuilt command')