Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Histogram equalization code in Matlab

Posted on 2003-03-03
Medium Priority
14,730 Views
Hi,
i'm in need for histogram equalization code written in Matlab.
thanks.
0
Question by:sherihan
• 2
• 2

LVL 2

Accepted Solution

xyzzer earned 100 total points
ID: 8058128
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

Author Comment

ID: 8060601
Hi Filip,
sherihan.
0

LVL 2

Expert Comment

ID: 8060889
How about some points if that helps You?

--Filip
0

Author Comment

ID: 8134937
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Progress
###### Suggested Courses
Course of the Month15 days, 23 hours left to enroll