2

I'm really confused with this technique.. I know that a histogram is the frequency for every value (I am working on gray-scale images) and I've produced a method to do that:

int[] populateHist (PImage x)
{
  x.loadPixels();
  int[] out = new int[256];
  for (int i = 0; i < x.pixels.length; i++)
  {
     out[(int)red(x.pixels[i])]++;
  }
  return out;
}

And a spreading function for the cumulative array:

int[] spreadFunc (int[] a)
{
  int[] out = new int[256];
  for (int i = 0; i < a.length; i++)
  {
    if (i == 0)
    {
      out[i] = (a[i]);
    }
    else
    out[i] = (a[i]) + (a[i-1]);
  }
  return out;
}

The next step is to normalize those values so is it correct to take the maximum value and divide all values by the same certain number so that the maximum is now 255?

Also, another thing I'm confused about is that even after normalizing the histogram, how will I be able to recreate the image with the spread pixel values?

1 Answer 1

0

First you obtain the CDF (cumulative distribution function). This is basically your " spreading function", but you should normalize it so that is goes from 0 to 1 (divide it by the number of pixels, use doubles).

Second, you remap the values of the pixels y = cdf(x)*255

Or do just y = cdf(x) and the remap linearly the min-max values to the 0-255 range, it's basically the same thing.

See eg http://en.wikipedia.org/wiki/Histogram_equalization#Implementation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.