Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2011 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/769847 to your computer and use it in GitHub Desktop.
Save anonymous/769847 to your computer and use it in GitHub Desktop.
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