%This demonstrates histogram equalization on the 200X200 clown image.
clear;load clown.mat;X=round(X*39999)+1;%Maximum value now 40000. Makes program simpler.
%Just scale equalized image to range from 0 to 1 or 0 to 255, as desired. M^2=(200)^2=40000.
%Horizontal axis: f_o and g_o now range from 0 to 40000 instead of from 0 to 255.
figure,imagesc(X),colormap(gray),axis off, title('Original clown image')
figure,hist(X(:),0.5+[0:39999]),title('Histogram p_f[f_o] of original clown image')
PX=hist(X(:),0.5+[0:39999]);FX=[0 cumsum(PX)];%Histogram and CDF of original image.
figure,plot(FX),title('CDF P_f[f_o] of original clown image')
Y=FX(X(:));%Equalization (Eq. (5.42)).
PY=hist(Y,0.5+[0:39999]);FY=[0 cumsum(PY)];%Histogram and CDF of equalized image.
figure,plot(FY),title('CDF P_g[g_o] of equalized clown image')
figure,hist(Y,0.5+[0:39999]),title('Histogram p_g[g_o] of equalized clown image')
figure,imagesc(reshape(Y,200,200)),colormap(gray),axis off,title('Histogram-equalized clown image')
