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
4
Medium Priority
?
14,730 Views
Last Modified: 2012-06-27
Hi,
i'm in need for histogram equalization code written in Matlab.
thanks.
0
Comment
Question by:sherihan
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

580 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