function [a] = hist_equal( name )
a = imread(name);
hist = histo(name);
cdf = zeros(1,256);
mincdf = 0;
for i=1:256
if(i==1)cdf(1) = hist(1);
else cdf(i) = cdf(i-1) + hist(i);
end
mincdf = min(mincdf,cdf(i));
end
cdf_sc = zeros(1,256);
for i = 1:256
cdf_sc(i) = round(((cdf(i) - mincdf)*(255))/(262144 - mincdf));
end
for i = 1:512
for j = 1:512
a(i,j) = cdf_sc(a(i,j) + 1);
end
end
histogram = zeros(1,256);
for i = 1:512
for j = 1:512
val = a(i,j) + 1;
histogram(val) = histogram(val) + 1;
end
end
x = 0:255;
imshow(a);
plot(x,histogram);
end
Published with MATLAB 7.14