from
Removal of unevenness of a histogram
by Bratati paul
Every local minima-maxima pair is replaced by a plate and histogram is smoothened
|
| Plated_hist.m |
%% Document Title
% This code removes the unevenness of a histogram to a great extent.
% Every local minima-maxima pair is replaced by a plate whose height is
% equal to the average height of the local minima-maxima pair and width
% is equal to the width of the local minima-maxima pair.Thus the histogram
% is plated and we get a smoother version of the original histogram at
% the cost of little approximation.
clear all;
i= imread('face6.jpg');
I= rgb2gray(i);
imhist(I);
a= imhist(I);
plot(a)
i=1;
k=1;
count=1;
x=0;
z=0;
if a(i)>=a(i+1), %if there is an increasing slope at the begining of the
while a(i)>=a(i+1), %histogram we move to the peak.It's the 1st local maxima
z=z+a(i); %The elements encountered so far are replaced by the
i=i+1; %average value.%
end
z=z+a(i);
while k<=i,
a(k)=floor(z/(i+1));
k=k+1;
end
end
while i<256 %This while loop eterates till the last element
start=i; %of the histogram.start holds the starting position of a plate%
while i+1<=256 & a(i)<=a(i+1),%This loop ends when a local crest is reached
x=x+a(i); %All the element on the way 2 a local crest is being added up
i=i+1;
end
while i+1<=256 & a(i)>=a(i+1), %This loop ends when the end of the
x=x+a(i); %increasing slope,i.e., a local peak
i=i+1; %is reached.
end
x=x+a(i); %The peak value is added as it doesnt get added inside the loop
if start==0, %The if block eterates only when there is an decreasing slope
count=i+1; %at the begining of the histogram
else
count=i-start+1; %In both the if & else block count conatins the no. of elements visited, by which the sum shud b divided to get the average value
i=start; %The begining point of a local minima-maxima pair is assigned to i
end %a plate is getting placed instead of the local-minima-maxima.
while i<=start+count-1,
a(i)=floor(x/count); %Every element of the local minima-maxima pair is
i=i+1; %getting replaced by the average value[floor(x/count)],
end %eteration ends as we reach the last element of the local minima-maxima pair,
x=0; %x is resetted.It holds the sum of a local minima-maxima pair.
end %control goes to line no.20, and another minima-maxima pair is encountered and plated
plot(a)
|
|
Contact us at files@mathworks.com