Greetings everybody.
i have an assigment on image proccesing and amongst other question one of them specifies:calculate the equalized histogram of a grayscale
image and show statistical data of your choice between the input and output images.
I am having trouble equalizing the histogram.I have googled around for a couple of days now and i think i could use some help, either im missing the whole picture or minor details that cause problems.
my code is below:
can anyone point out anything that might help?Code:// original histogram
for (i=0; i<lines; i++)
for (j=0; j<columns; j++)
hist[image_in[i][j]]++;
//histogram max and min
int hmax=-1,hmin=257;
for(int i=0;i<256;i++)
{
if (hist[i]>hmax)
hmax=hist[i];
if (hist[i]<hmin)
hmin=hist[i];
}
// Probability table
float prt[256];
int pixels=lines*columns;
for(int i=0;i<256;i++);
prt[i]=hist[i]/pixels;
// CumulativeDistributionFunction
float cdfmax=-1,cdfmin=257;
float cdf[256];
cdf[0]=prt[0];
for(int i=1;i<256;i++)
{
cdf[i]=prt[i]+cdf[i-1];
if(cdf[i]>cdfmax)
cdfmax=cdf[i];
if(cdf[i]<cdfmin)
cdfmin=cdf[i];
}
// final image
for (int i=0;i<lines;i++)
{
for(int j=0;j<columns;j++)
{
image_out[i][j]=(unsigned char)(((cdf[image_in[i][j]]-cdfmin)/(pixels-cdfmin))*255);
}
}
im thinking that my equalization formula is wrong, i might have incorrectly translated the mathematical formula from wikipedia to C code but i cant figure out why.
Thanks in advance