Saturday, September 14, 2013

edge detection of histogram - python

edge detection of histogram - python

Basically I have some data that I have mad a histogram from. No great
difficulty there, just use matplotlib.pyplot.hist(data,bins=num) However,
I want to do a kind-of Sobel edge detection where basically the ith
histogram bar/bin (whatever the jargon is) becomes
-2*(i-1)th+0*(i)th+2*(i+1)th I have worked out/found out that you can do
(my data is in columnated txt files)
import matplotlib.pyplot as plt
alldata = np.genfromtxt('filename', delimiter=' ')
data = alldata[:,18]
n,bins,patches = plt.hist(data,bins=30)
Which returns/gives
>>> n
array([3,0,3,3,6,1,...etc])
>>> bins
array([13.755,14.0298,14.3046,... etc])
>>> patches
<a list of 30 Patch objects>
Here I can perform my operation on n to get my sobel-filtered stuff, (Side
note: I just do this iteratively over the array is there an easier way
with something like a = [-2,0,2])
So, my question and problem! I have no idea how to then reconstruct the
result as a histogram or line-plot ... AND keep the same horizontal axis
bins

No comments:

Post a Comment