# Histogram equalization code in Matlab

Hi,
i'm in need for histogram equalization code written in Matlab.
thanks.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I don't know anything about Matlab yet, but I've done the task in C++:

void cDIB::Smooth(void) {
int x,y,i;
float pc[3][256];
float sc[3][256];

for (i=0; i<256; i++)
pc[0][i]=(float)histo[0][i]/(float)(Width*Height);// storing the histo in "pc" (probability of a color) array

sc[0][0]=pc[0][0];
for (i=1;i<256;i++) //Counting smoothed values
sc[0][i]=sc[0][i-1]+pc[0][i]; //storing them in "sc" array (smoothed color)

for(y=0;y<Height;y++)
for(x=0;x<Width;x++)
setpixel(x,y,(float)255*sc[0][pixel(x,y)]);
//drawing the pixels with smoothed values
}

--Filip
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Hi Filip,
sherihan.
0
Commented:
How about some points if that helps You?

--Filip
0
Author Commented:
here is the code i've written for histogram equalization in Matlab.
hope it is useful

clear all
l=256;

[m,n]=size(image1);
len=m*n;
image2=reshape(image1,len,1);

histogram = hist(image2,[0:l-1]);

cumhist(1)= histogram(1);
for i=2:l
cumhist(i)= cumhist(i-1)+ histogram(i);
end

for i=1:l
t(i)=round(((l-1)/(len))*cumhist(i));
end

newimage=zeros(len,1);

for i=2:l
tx(i-1)=t(i)
end

for i=1:len
if image2(i)~=0
newimage(i)=tx(image2(i));
else
newimage(i)=t(1);
end
end

finalimage=reshape(newimage,m,n);

finalhistogram=hist(newimage,[0:l-1]);

mean1=mean(image1);
mean2=mean(finalimage);

s2= std(finalimage);
%s1=std(image2);

figure(1),subplot(3,1,1),stem([0:l-1],histogram),title('histogram, original')
subplot(3,1,2),stem([0:l-1],t),title('transformation')
subplot(3,1,3),stem([0:l-1],finalhistogram),title('histogram, equalized')
figure(2),subplot(1,2,1),image(image1),colormap('gray'),title('original')
subplot(1,2,2),image(finalimage),colormap('gray'),title('equalized')

0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.