Need to run though an image in python and essentially calculate the average location of all acceptable pixels within a certain boundary. The image is black and white. The acceptable pixels have a value of 255 and the unacceptable pixels have a value of zero. The image is something like 2592x1944 and takes maybe 15 seconds to run. This will need to be looped several times. Is there a faster way to do this?
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)

