python - 从半径为 R1 和 R2 的圆环内的图像中提取数据点

标签 python image mode

我有一张尺寸为 3000 * 3000 像素的图像。我首先找到我感兴趣的区域的中心,比如位置 (1000,2000)。我想提取 R1 = 10 像素、R2 = 20 像素的环内数据,并找到环内数据的模式。是否有任何 python 例程可以做到这一点,或者有任何智能和简洁的方法来实现它?我知道 photutils.aperture_photometry 可以获得环面的总和,但不是每个像素的任何单独数据点。

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

最佳答案

没有任何答案……惊呆了。我有两个非常简单的循环函数来做到这一点。

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)

有更好的实现方式吗?

关于python - 从半径为 R1 和 R2 的圆环内的图像中提取数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43649805/

相关文章:

mysql - 如何在与另一个表连接之前找到一组数据的模式?

python - 当 multiprocessing 使用 fork 作为起始方法时,为什么传递给 Pool.map 的函数会被 pickle ?

python - 如何使 Sprite 沿着pygame中的曲线移动到点

python - Tensorflow 模型输入形状错误 : Input 0 of layer sequential_11 incompatible with layer: rank undefined, 但层需要定义等级

android - 适用于 Android 的 Titanium/Appcelerator : Multiple density images not found

javascript - 如何获取 CSS 位置 : fixed for a background image to work properly?

python - 如何从 pandas 的每一列中获取 n 个最多的列值

python - S4 对象中的属性装饰器 (R)

ios - Xcode 6.1 对 iPhone 6 和 4s 模拟器使用相同的 2x 图像

C 中的计算模式——​​数学有点错误