Skip to content

Instantly share code, notes, and snippets.

/gist:769847
Created Jan 7, 2011

Embed
What would you like to do?
LocateWhiteDot.py
(c) 2010 Narendra Sisodiya, http://narendrasisodiya.com , released under MIT license
def LocateWhiteDot(image):
width,height=image.size
### Scan Column
xStart = 0
weHaveXStart = 0
xEnd = 0
for i in range(0,width):
blank = 0
for j in range(0,height):
#Now Scanning i-th Column... (Column number, Row number)
blank = blank + image.getpixel((i,j))
if blank != 0 :
if weHaveXStart == 1:
xEnd = i
else:
xStart = i
weHaveXStart = 1
### Scan rows
RowNum = []
yStart = 0
weHaveYStart = 0
yEnd = 0
for j in range(0,height):
blank = 0
for i in range(0,width):
#Now Scanning j-th Row... (Column number, Row number)
blank = blank + image.getpixel((i,j))
if blank != 0 :
if weHaveYStart == 1:
yEnd = j
else:
yStart = j
weHaveYStart = 1
xMid = (xStart + xEnd)/2
yMid = (yStart + yEnd)/2
return (xMid,yMid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.