Histogram equalization is used to improve the contrast of an image. The algorithm is very easy. In a normal image you have greater amount of detail in some end of the gray scale. In other words if you see the histogram of a normal image all the pixels will be near some gray scale value. (Histogram is nothing but the graph plotting number of pixels vs gray scale value). In histogram equalization you divide the pixels equally between all gray scale values. If you see the histogram of the new image (after histeq) you can clearly see that the pixels are distributed equally throughout.