我有一个与对象位置对应的稀疏(100k / 20000 ^ 2)2-D布尔numpy蒙版。
我想更新遮罩,将原始遮罩中True像素的某个半径范围内的所有像素设置为True。换句话说,将delta函数响应与每个位置的圆孔/内核(在本例中)进行卷积。
由于主阵列很大(即20000 x 20000),并且有10万个位置,我需要速度和内存效率......
例如(见numpy create 2D mask from list of indices [+ then draw from masked array]):
import numpy
from scipy import sparse
xys=[(1,2),(3,4),(6,9),(7,3)]
master_array=numpy.ones((100,100))
coords = zip(*xys)
mask = sparse.coo_matrix((numpy.ones(len(coords[0])),coords),\
shape= master_array.shape, dtype=bool)
# Now mask all pixels within a radius r of every coordinate pair in the list
mask = cookieCutter(mask,r) # <--- I need an efficient cookieCutter function!
# Now sample the masked array
draws=numpy.random.choice(master_array[~mask.toarray()].flatten(),size=10)
谢谢!
(来自numpy create 2D mask from list of indices [+ then draw from masked array])