w: width of image
h: height of image
Lmin : Min gray level of some gray image, relevant to image bit depth, in generally, 0
Lmax: Max gray level of some gray image, relevant to image bit depth, in generally, 255
1. statistics occuring frequency of gray level
for(i = 0; i < h; i++)
for(j = 0; j < w; j++) n[graylevel[i][j]]++;
2. normalization
for(i = 0; i < Lmax; i++) p[i] = n[i] / (w * h);
3. accumulate probability
p[i] += p[i - 1]; i = 0, ..., Lmax
4. equalized image
for(i = 0; i < h; i++)
for(j = 0; j < w; j++) newgraylevel[i][j] = p[graylevel[i][j] * (Lmax - Lmin) + Lmin