I have an image where I am trying to compute the line integral (sum) along a circular path. My idea to approach this is:
- Compute the circular path to sum over
- Mask the image based on the path, where everything except whatever pixels coincide with the path are zeroed out.
- Sum over all image pixel
I am currently stuck between steps one and two, where I can't figure out how to generate a circle on the same grid as the image.
In code:
from scipy.stats import multivariate_normal
radius = 2
# Draw arbitrary image
x, y = np.mgrid[-5:5:.1, -5:5:.1]
img = multivariate_normal.pdf(np.dstack((x, y)), cov=[[1, 0.7], [0.7, 1]])
# generate circle with desired radius
circle = radius*np.exp(1j*np.linspace(-np.pi, np.pi, 100))
pyplot.pcolormesh(x, y, img)
pyplot.plot(np.real(circle), np.imag(circle), '-w')
pyplot.show()
Question:
How to use the circle to mask the image pixels coinciding with this circle?