首页 > 解决方案 > 计算每个“像素”中的数据点

问题描述

我在编写一个函数时遇到问题,该函数将扫描(例如)10×10 像素区域以获取具有一定平均值的数据点数量。我的问题是在 x 轴上获得一个 10×10 的区域,同时保持 y 轴不变,然后一旦 x 轴“扫描”完成,在 y 轴上向上移动 10 个像素并在 x 轴上重复扫描。

# creating a standard to compare images against.
# from corner dark region with a lack of sources.
baseline = np.mean(
           M91_master_image[0].data[1800:2000, 1800:2000]
    + 4 * (M91_master_image[0].data[1800:2000, 1800:2000].std())
)  

mst_image_data = M91_master_image[0].data

o_y = 400 
o_y2 = 2000 
o_x = 400 
o_x2 = 2000
s = 10  # pixel increments 

x_array = []
y_array = []

while o_x < o_x2: 
    # print(o_x)
    counts = mst_image_data[o_x:o_x + s, o_y:o_y + s]
    if counts.mean() > baseline: 
        x_pos_c = (o_x + (o_x + s))/2 
        # print(x_pos_c)
        x_array = np.append(x_array, x_pos_c)
        # print(o_x)
        y_pos_c = (o_y + (o_y + s))/2
        y_array = np.append(y_array, y_pos_c)
    o_y += s 
    o_x += s
    
print(x_array, y_array)

从图像中您可以看到我得到的是对角线:

在此处输入图像描述

标签: pythonpython-3.xloops

解决方案


推荐阅读