private byte[] Equalize( int[] histogram, long numPixel )
{
byte[] equalizedHistogram = new byte[256];
float coef = 255.0f / numPixel;
// calculate the first value
float prev = histogram[0] * coef;
equalizedHistogram[0] = (byte) prev;
// calcualte the rest of values
for ( int i = 1; i < 256; i++ )
{
prev += histogram[i] * coef;
equalizedHistogram[i] = (byte) prev;
}
return equalizedHistogram;
}
}