Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with histogram equalization algorithm (http://www.go4expert.com/forums/histogram-equalization-algorithm-t19825/)

 metamofia 20Oct2009 15:03

Problem with histogram equalization algorithm

Hi, im doing histogram equalization on 8-bit images of sizes 512*512 and 256*256..
Here is my code below:
Code:

``` void CLEO_MedivisionView::OnUpdateToolsHistogramequalization(CCmdUI *pCmdUI) { // TODO: Add your command update UI handler code here if (fileopen) { pCmdUI->Enable(true); } else { pCmdUI->Enable(false); } }   void CLEO_MedivisionView::OnToolsHistogramequalization() { int i; unsigned int array1[256]; unsigned int cdf[256]; unsigned int arrayhe[256];       //** Step 1 **\\ for (i=0;i<256;i++) { array1[i]=0; } if (no_of_rows == 512 && no_of_cols == 512) { for (i=0; i<262144; i++) { array1[image[i]]++; } } else if (no_of_rows == 256 && no_of_cols == 256) { for (i=0; i<65536; i++) { array1[image256[i]]++; } }     //** Step 2 **\\ cdf[0] = array1[i]; // finding cumulative distribution for (i=1; i<256; i++) { cdf[i] = array1[i] + cdf[i-1]; } for (i=0;i<256;i++) // zeros out all the element in the array { arrayhe[i]=0; } for (i=0; i<256; i++) // applying the HE algorithm { arrayhe[i] = (cdf[i]*255/262144)+0.5; }       }```
Im sure that step 1 is correct..

however when i toggle a breakpoint on cdf[i] in step 2 and when i wanted to check the values inside it and make sure its cumulative frequency compared to array1[i] which is just frequency.. When i got the values, i get random flow of number ie: '02ex47810'..

Any ideas why is this so? Thanks

 xpi0t0s 21Oct2009 03:35

Re: Problem with histogram equalization algorithm

Code:

```for (i= !!! 1 !!!; i<256; i++) for (i= !!! 0 !!!; i<256; i++)```
You've reintroduced the "not starting at zero" bug.

 metamofia 21Oct2009 06:18

Re: Problem with histogram equalization algorithm

What do u mean?

 xpi0t0s 21Oct2009 13:07

Re: Problem with histogram equalization algorithm

Sorry, my mistake, it's a different bug.
Code:

`cdf[0] = array1[i];`
At this point, i is either 262144 or 65536 having just come out of the "if (no_of_rows == 512 && no_of_cols == 512)" block. So array1[i] is undefined, and all your values after that are critically dependent on this, so you get garbage.

 metamofia 22Oct2009 07:27

Re: Problem with histogram equalization algorithm

All right thanks. Thats settled.. IM getting the cumulative values for cdf[] now..

My second and probably the last issue is how do i display the NEW intensity values on the old image, after this code:

Code:

```unsigned int arrayhe[256];   for (i=0; i<256; i++) // applying the HE algorithm { arrayhe[i] = (cdf[i]*255/262144)+0.5; }```
Do help me out on this thanks.

 xpi0t0s 22Oct2009 14:42

Re: Problem with histogram equalization algorithm

How did you read the previous intensity values from the image?

 metamofia 23Oct2009 10:03

Re: Problem with histogram equalization algorithm

hi thanks for getting back to me.. im done with the equalization.. i got a new question on segmentation which i will post in another thread

 All times are GMT +5.5. The time now is 23:57.