/usr/lib/python2.7/dist-packages/dipy/core/histeq.py is in python-dipy 0.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import numpy as np
def histeq(arr, num_bins=256):
""" Performs an histogram equalization on ``arr``.
This was taken from:
http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html
Parameters
----------
arr : ndarray
Image on which to perform histogram equalization.
num_bins : int
Number of bins used to construct the histogram.
Returns
-------
result : ndarray
Histogram equalized image.
"""
#get image histogram
histo, bins = np.histogram(arr.flatten(), num_bins, normed=True)
cdf = histo.cumsum()
cdf = 255 * cdf / cdf[-1]
#use linear interpolation of cdf to find new pixel values
result = np.interp(arr.flatten(), bins[:-1], cdf)
return result.reshape(arr.shape)
|