Extract data points from image in annular space with radius R1 and R2
I have a 3000 * 3000px image. I first find the center of my area of interest, say at position (1000,2000). I want to extract data into ring space with R1 = 10 pixels, R2 = 20 pixels and find the data mode in ring space. Is there some python routine for this, or any smart and concise way to implement it? I know I photutils.aperture_photometry
can get the sum of the ring, but not the individual data points at each pixel.
import numpy as np
data = np.random.uniform(0,10,size=(3000,3000))
center = (1000,2000) #### in pixel space
R1 = 10 #### pixels
R2 = 20 #### pixels
....
+3
source to share
1 answer
No answer ... Surprised. I have a very simple two loop function to do this.
imin = center[0] - R2 imax = center[0] + R2 + 1 jmin = center[1] - R2 jmax = center[1] + R2 + 1 target = [] for i in np.arange(imin, imax): for j in np.arange(jmin, jmax): ij = np.array([i,j]) dist = np.linalg.norm(ij - np.array(center)) if dist > R1 and dist <= R2: target.append([i,j,data[i][j]]) target = np.array(target)
Any better implementation?
0
source to share