Created
January 21, 2013 20:52
-
-
Save andrewgiessel/4589258 to your computer and use it in GitHub Desktop.
histogram normalization with numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def histeq(im,nbr_bins=256): | |
#get image histogram | |
imhist,bins = np.histogram(im.flatten(),nbr_bins,normed=True) | |
cdf = imhist.cumsum() #cumulative distribution function | |
cdf = 255 * cdf / cdf[-1] #normalize | |
#use linear interpolation of cdf to find new pixel values | |
im2 = np.interp(im.flatten(),bins[:-1],cdf) | |
return im2.reshape(im.shape), cdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to interpolate a CDF at a value say 0.5 to get a scalar value as a result?