I have this procedure for aligning the histogram of a photo:
def histeq(im,nbr_bins=256):
imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
cdf = imhist.cumsum()
cdf = 255 * cdf / cdf[-1]
im2 = interp(im.flatten(),bins[:-1],cdf)
return im2.reshape(im.shape), cdf
im = array(Image.open('Unequalized.jpg').convert('L'))
im2,cdf = histeq(im)
plt.imshow(im2)
plt.savefig("outputhisto.jpg")
When I run this with a picture on the wiki page for histogram alignment , this leads to the following:

Instead of properly adjusting the contrast of the image to something along the lines of this . What am I doing wrong?
source
share