?
Solved

Histogram equalization code in Matlab

Posted on 2003-03-03
4
Medium Priority
?
14,640 Views
Last Modified: 2012-06-27
Hi,
i'm in need for histogram equalization code written in Matlab.
thanks.
0
Comment
Question by:sherihan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
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

by:sherihan
ID: 8060601
Hi Filip,
thanks for your help.
sherihan.
0
 
LVL 2

Expert Comment

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

--Filip
0
 

Author Comment

by:sherihan
ID: 8134937
here is the code i've written for histogram equalization in Matlab.
hope it is useful

clear all
image1=imread('high2.jpg');
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question