需要在python中运行一个图像,基本上计算特定边界内所有可接受像素的平均位置.图像是黑白的.可接受像素的值为255,不可接受像素的值为零.该图像类似于2592x1944,运行可能需要15秒.这需要循环几次.有没有更快的方法?
goodcount = 0
sumx=0
sumy=0
xindex=0
yindex=0
for row in mask:
yindex+=1
xindex=0
for n in row:
xindex+=1
if n == 255:
goodcount += 1
sumx += xindex
sumy += yindex
if goodcount != 0:
y = int(sumy / goodcount)
x = int(sumx / goodcount)