Created
April 13, 2020 17:32
-
-
Save louismullie/127f96261d1d3bc57c2ef941f76bbccb to your computer and use it in GitHub Desktop.
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 image_histogram_equalization(image, number_bins=256): | |
# from http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html | |
# get image histogram | |
image_histogram, bins = np.histogram(image.flatten(), number_bins, density=True) | |
cdf = image_histogram.cumsum() # cumulative distribution function | |
cdf = 255 * cdf / cdf[-1] # normalize | |
# use linear interpolation of cdf to find new pixel values | |
image_equalized = np.interp(image.flatten(), bins[:-1], cdf) | |
return image_equalized.reshape(image.shape), cdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment