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

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

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
Asked:
killaz4life
  • 6
  • 4
1 Solution
 
Infinity08Commented:
Can you tell us the exact problem you have, as well as the relevant code you have ?
0
 
killaz4lifeAuthor 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
 
Infinity08Commented:
>>                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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
killaz4lifeAuthor Commented:
What should i do then?? Help me with the function, what I do wrong??
0
 
Infinity08Commented:
As i asked : what do you want do do ?
0
 
killaz4lifeAuthor 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
 
Infinity08Commented:
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
 
Infinity08Commented:
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
 
killaz4lifeAuthor 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
 
Infinity08Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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