I am trying to calculate the empirical cumulative distribution of images in Python. What is the best practice in doing so? And also I need the result to be stored in an array so that I can use it in further steps of my analysis.
I am using this function and I am not sure if it is the right way to do it:
`def ecdf(data):
x = np.sort(data.flatten())
n = x.size
y = np.arange(1, n+1) / n
return (x,y)`
Here is how I am doing this now and it works (for a grayscale image):
def Ghist(image):
'''compute eCDF of an image'''
data_flatten = image.flatten()
data_sort = np.sort(data_flatten)
values, bins = np.histogram(data_sort, normed=True)
return (bins, values)
def ecdf(image):
'''compute eCDF of an image'''
data_flatten = image.flatten()
data_sort = np.sort(data_flatten)
values, bins = np.histogram(data_sort, normed=True)
data_cum = np.cumsum(values)
return (bins, data_cum)