0% found this document useful (0 votes)
2 views

Program 2

The document outlines a MATLAB script for performing histogram equalization on an image. It reads an image, converts it to grayscale, computes the probability density function (PDF) and cumulative distribution function (CDF), and then applies the equalization process. Finally, it displays the original image, the equalized image, and their respective histograms in a subplot format.

Uploaded by

215 Logavani BK
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program 2

The document outlines a MATLAB script for performing histogram equalization on an image. It reads an image, converts it to grayscale, computes the probability density function (PDF) and cumulative distribution function (CDF), and then applies the equalization process. Finally, it displays the original image, the equalized image, and their respective histograms in a subplot format.

Uploaded by

215 Logavani BK
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

%2. Histogram Equalization.

close all;
clear ;
clc;
warning off;
a=imread('veg.png')
a=rgb2gray(a);
b=size(a);
freq_counts=zeros(1,256);
for i=1:b(1)
for j=1:b(2)
for k=0:255
if(a(i,j))==k
freq_counts(k+1)=freq_counts(k+1)+1;
end
end
end
end
%generating pdf
pdf=(1/(b(1)*b(2)))*freq_counts;
%generating cd
cdf=zeros(1,256);
cdf(1)=pdf(1);
for i=2:256
cdf(i)=cdf(i-1)+pdf(i);
end
cdf=round(255*cdf);
eq=zeros(b);
for i=1:b(1)
for j=1:b(2)
f=(a(i,j)+1);
eq(i,j)=cdf(f);
end
end
hist2=zeros(1,256);
for i=1:b(1)
for j=1:b(2)
if (eq(i,j)==k)
hist2(k+1)=hist2(h+1)+1;
end
end
end
subplot(2,2,1);
imshow(uint8(a));title('original image')
subplot(2,2,3);
imshow(uint8(eq));title('histogram equalized image')
subplot(2,2,2);
stem(freq_counts);title('histogram of original image')
subplot(2,2,4);
stem(hist2);title('histogram of equalized image')

You might also like