Take data from a circle in python

I study how the intensity of the ring changes depending on the angle. Here is an example image:

enter image description here

What I would like to do is take a circle of values โ€‹โ€‹from the inside of the center of this donut and build them against the corner. What I'm doing now is to use scipy.ndimage.interpolation.rotate and take slices radially around the ring and extract a maximum of two peaks and apply them depending on the angle.

crop = np.ones((width,width)) #this is my image slices = np.arange(0,width,1) stack = np.zeros((2*width,len(slices))) angles = np.linspace(0,2*np.pi,len(crop2)) for j in range(len(slices2)): # take slices stack[:,j] = rotate(crop,slices[j],reshape=False)[:,width] 

However, I do not think this does what I am really looking for. I am basically trying to extract the data I need. I also tried applying a mask that looks like this:

enter image description here

but then I donโ€™t know how to get the values โ€‹โ€‹inside this mask in the correct order (i.e. in the ascending order of the angle 0 - 2pi)

Any other ideas would be very helpful!

+6
source share
1 answer

I made another input image to help validate:

 import numpy as np import scipy as sp import scipy.interpolate import matplotlib.pyplot as plt # Mock up an image. W = 100 x = np.arange(W) y = np.arange(W) xx,yy = np.meshgrid(x,y) image = xx//5*5 + yy//5*5 image = image / np.max(image) # scale into [0,1] plt.imshow(image, interpolation='nearest', cmap='gray') plt.show() 

Alternative input image

To select values โ€‹โ€‹from the circular paths in the image, we first construct an interpolator, because we want to access arbitrary locations. We also vectorize it faster. Then we create the coordinates of the points N on the circle circumference using the parametric definition of the circle x(t) = sin(t), y(t) = cos(t) .
N must be at least twice the circumference (Nyquist-Shannon sampling theorem).

 interp = sp.interpolate.interp2d(x, y, image) vinterp = np.vectorize(interp) for r in (15, 30, 45): # radii for circles around image center xcenter = len(x)/2 ycenter = len(y)/2 arclen = 2*np.pi*r angle = np.linspace(0, 2*np.pi, arclen*2, endpoint=False) value = vinterp(xcenter + r*np.sin(angle), ycenter + r*np.cos(angle)) plt.plot(angle, value, label='r={}'.format(r)) plt.legend() plt.show() 

circles selected from the center.

+3
source

All Articles