Professional Documents
Culture Documents
___________________________________________________________________________
Histogram
This histogram is a graph showing the number of pixels in an
image at each different intensity value found in that image. For
an 8-bit grayscale image there are 256 different possible
intensities, and so the histogram will graphically display 256
numbers showing the distribution of pixels amongst those
grayscale values.
Mathematical Expression for Histogram is
PXi=Px=i=nin , 0≤i≤L
L being the total number of gray levels in the image, n being the total number of pixels in the
image, and PXi being in fact the image's histogram for pixel value i, normalized to [0,1].
Example:
Consider 1D Data X(n)=[1, 2, 3, 4, 1, 3, 4, 3, 2, 3, 5, 3, 2, 1, 1]
Then Histogram of above 1D Data is
Data Histogram Count
1 4
2 3
3 5
4 2
5 1
The above histogram can be plotted using Graph
Histogram Equalization
Let us also define the cumulative distribution function corresponding to Pxas
We would like to create a transformation of the form y = T(x) to produce a new image {y},
such that its CDF will be linearized across the value range, i.e.
For some constant K. The properties of the CDF allow us to perform such a transform. It is
defined as
Notice that the T maps the levels into the range [0, 1]. In order to map the values back into
their original range, the following simple transformation needs to be applied on the result:
close all;
clc;
clear all;
imgorig=imread('cameraman.tif');
figure,imshow(uint8(imgorig));
title('Original Image');
[m,n]=size(imgorig);
histt(1,1:256)=0;
for i=1:m
for j=1:n
index=imgorig(i,j);
histt(1,index+1)=histt(1,index+1)+1;
end
end
figure,bar(0:255,histt,0.001);
title('Histrogram of Original Image');
xlabel('Gray Level L');
ylabel('Histogram Count n');
for i=0:255
sum1=0;
for j=0:i
sum1=sum1+histt(1,j+1);
end
cdfx(1,i+1)=sum1;
end
%% show CDF
figure,bar(0:255,cdfx,0.001);
title('CDF');
%% Histogram Equalization
z=sort(cdfx);
count=1;
while(z(1,count)==0)
count=count+1;
end
temp=z(1,count);
cdfmin=temp;
for i=1:m
for j=1:n
v=imgorig(i,j);
c=cdfx(1,v+1);
if(c~=0)
calcul=((cdfx(1,v+1)-cdfmin)/((m*n)-cdfmin))*255;
imgnew(i,j)=round(calcul);
end
end
end
imgnew1=uint8(imgnew);
figure,imshow(uint8(imgnew));
title('Equalized Image');
for i=1:m
for j=1:n
index=imgnew1(i,j);
histt(1,index+1)=histt(1,index+1)+1;
end
end
figure,bar(0:255,histt,0.001);
title('Histrogram of Equalized Image');
xlabel('Gray Level L');
ylabel('Histogram Count n');
for i=1:m
for j=1:n
msee=msee+cc(i,j);
end
end
msee=msee/(m*n)
maxx=double(max(max(imgorig)))
psnrr=10*log10((maxx.^2/msee))
PSNR=10*log10MAXi2MSE
OR
PSNR=10*log10MAXiMSE