以以下数组为例:
points=np.array([[1,2],[1,3],[1,4],[2,4],[3,4],[4,4],[5,4],[6,4],[1,5],[1,6],[1,8],[1,9],[1,10],[1,11],[1,13]])
我想找到邻居像素
我的代码如下:
def npixel(pixel):
pixels= np.array([[pixel[0]-1, pixel[1]-1], [pixel[0]-1, pixel[1]], [pixel[0]-1, pixel[1]+1], [pixel[0], pixel[1]-1],
[pixel[0], pixel[1]+1], [pixel[0]+1, pixel[1]-1], [pixel[0]+1, pixel[1]], [pixel[0]+1, pixel[1]+1]])
return pixels
points=np.array([[1,2],[1,3],[1,4],[2,4],[3,4],[4,4],[5,4],[6,4],[1,5],[1,6],[1,8],[1,9],[1,10],[1,11],[1,13]])
for x in points:
if p in npixel(x):
count+=1
print('neigbour pixel',p)
print("count",count)
期望输出:
pixel:[1,2]
neigbour-pixel:[1,3]
count:1
pixel:[1,3]
neigbour-pixel:[1,2],[1,4]
count:2
so on
试图复制您的desidered输出,但不确定它是否是您所寻找的结果:
我的输出:
印刷品
和返回的数组:
这是我的方法。为了便于操作,我将numpy数组更改为list
输出:
相关问题 更多 >
编程相关推荐