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?