[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 409

Histogram equalization

Hi there,
I have been having alot of trouble trying to make the histogramn equalization work in c++ and this laplacian smoothing is not working at all with me.
My program only enhances gray scale currently so im not involved with any rgb being stored and I am sending to my functions the array image2D[row][col] that contains the pixel values.
Thankyou
0
killaz4life
• 6
• 4
1 Solution

Commented:
Can you tell us the exact problem you have, as well as the relevant code you have ?
0

Author Commented:
void CImgProcess::histogramEqualisation()
{

for(int r=0;r<ROW;r++)
for(int c=0;c<COL;c++)
{
double value=image2D[r][c]; value = value/255;
value=value*255/(ROW*COL);
image2D_Buffer[r][c]=(unsigned char)value;
}

}
0

Commented:
>>                value=value*255/(ROW*COL);
What do you intend to do here ?

In general value will end up to be 0 in most cases. I'm sure that's not what you want.
0

Author Commented:
What should i do then?? Help me with the function, what I do wrong??
0

Commented:
As i asked : what do you want do do ?
0

Author Commented:
I want to do histogram equalization thas what I want to do! Ok I get rid of value=value/256;
I really hope u know what histogram equalization is.
0

Commented:
I had to look it up, and here's the step-by-step way of implementing it :

1) calculate the histogram for the image ... ie. count the distinct pixel values in the image (loop over the image, and increase the counter for the current pixel value by 1).

2) fill another array containing the sum of the histogram values upto and including that value (ie. cumulative). Normalise this array by multiplying it with 255/(COLS*ROWS)

3) transform the input image

Or in code :

int histogram[256] = { 0 };
int r, c, i;

// step 1 : calculation of histogram
for (r = 0; r < ROW; r++) {
for (c = 0; c < COL; c++) {
histogram[image2D[r][c]]++;
}
}

// step 2 : cumulative histogram and normalisation
for (i = 1; i < 256; i++) {
histogram[i] += histogram[i - 1];
}
for (i = 0; i < 256; i++) {
histogram[i] = (int) ((((double) histogram[i]) / ((double) (ROW * COL))) * 255);
}

// step 3 : transform image
for (r = 0; r < ROW; r++) {
for (c = 0; c < COL; c++) {
image2D_Buffer[r][c] = histogram[image2D[r][c]];
}
}
0

Commented:
And here's a nice link explaining the process :

http://www.generation5.org/content/2004/histogramEqualization.asp

btw, I didn't test the code, so you'll have to do that before assuming it's 100% correct !!
0

Author Commented:
I just tested the code you gave me, there some reason I only see blocks rather than image enhancement. Could it be possible the int is doing any effect?
0

Commented:
What do you mean by "blocks" ?

The code I gave was not tested, and was written from my head ... so there could be errors present ... It was meant to give you an idea about the code rather than to use it as is.

In any wase, the big lines should be ok. You might want to check the intermediate outputs to see if the result is as expected.

Try it on an image you know should be enhanced by this process (eg. the ones on the site i referred to earlier).
0

Featured Post

• 6
• 4
Tackle projects and never again get stuck behind a technical roadblock.