2017-04-27 28 views
3

我有一個尺寸爲3000 * 3000像素的圖像。我首先找到我感興趣的領域的中心,說在位置(1000,2000)。我想提取R1 = 10像素,R2 = 20像素的環內數據,並找出環內數據的模式。有沒有任何python例程來實現它或者任何聰明和簡潔的方式來實現它?我知道photutils.aperture_photometry可以得到環的總和,但不是每個像素的任何單個數據點。從半徑爲R1和R2的環形空間內的圖像中提取數據點

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 
.... 

回答

0

沒有任何答案......驚訝。我有非常簡單的兩個循環功能來做到這一點。

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) 

有沒有更好的實現?

相關問題