(eyeimg, pupthreshold=50, glintthreshold=200, \
	glint=True, mode='diameter', debugindex=None)
return v['px'], v['py'], v['ps'], v['gx'], v['gy']
Finds the pupil and the glint in a single image of an eye, and
	returns the relevant parameters. Parameters that cannot be found
	will be None.
	
	Arguments
	
	eyeimg		-	A numpy.ndarray with unsigned, 8-bit
					integers that reflect the greyscale values
					of what is assumed to be an eye.
	
	Keyword Arguments
	
	glint			-	A Boolean that indicates whether the glint
					(the corneal reflection) should also be
					detected. Default = True.
	
	mode			-	A string that indicates how the pupil size
					should be reported.
					'diameter' reports the width of the rect in
					which the thresholded pupil fits
	
	Returns
	[px, py, ps, gx, gy]
				-	px is an integer indicating the pupil's
					likely horizontal position within the image.
					py is an integer indicating the pupil's
					likely vertical position within the image.
					ps is an integer indicating the pupil's
					size in pixels. The size reflects the width
					of the rect in which the pupil falls when
					mode=='diameter', or the total amount of
					thresholded pixels when mode'surface'.
					gx is an integer indicating the pupil's
					likely horizontal position within the image.
					gy is an integer indicating the pupil's
					likely vertical position within the image.
					All of these values can be None if they
					could not be obtained.
Finds the pupil and the glint in a single image of an eye, and
	returns the relevant parameters. Parameters that cannot be found
	will be None.
	
	Arguments
	
	eyeimg		-	A numpy.ndarray with unsigned, 8-bit
					integers that reflect the greyscale values
					of what is assumed to be an eye.
	
	Keyword Arguments
	
	glint			-	A Boolean that indicates whether the glint
					(the corneal reflection) should also be
					detected. Default = True.
	
	mode			-	A string that indicates how the pupil size
					should be reported.
					'diameter' reports the width of the rect in
					which the thresholded pupil fits
	
	Returns
	[px, py, ps, gx, gy]
				-	px is an integer indicating the pupil's
					likely horizontal position within the image.
					py is an integer indicating the pupil's
					likely vertical position within the image.
					ps is an integer indicating the pupil's
					size in pixels. The size reflects the width
					of the rect in which the pupil falls when
					mode=='diameter', or the total amount of
					thresholded pixels when mode'surface'.
					gx is an integer indicating the pupil's
					likely horizontal position within the image.
					gy is an integer indicating the pupil's
					likely vertical position within the image.
					All of these values can be None if they
					could not be obtained.
Finds the pupil and the glint in a single image of an eye and returns the relevant parameters . Parameters that cannot be found will be None . Arguments eyeimg - A numpy . ndarray with unsigned 8 - bit integers that reflect the greyscale values of what is assumed to be an eye . Keyword Arguments glint - A Boolean that indicates whether the glint ( the corneal reflection ) should also be detected . Default = True . mode - A string that indicates how the pupil size should be reported . diameter reports the width of the rect in which the thresholded pupil fits Returns [ px py ps gx gy ] - px is an integer indicating the pupil s likely horizontal position within the image . py is an integer indicating the pupil s likely vertical position within the image . ps is an integer indicating the pupil s size in pixels . The size reflects the width of the rect in which the pupil falls when mode == diameter or the total amount of thresholded pixels when mode surface . gx is an integer indicating the pupil s likely horizontal position within the image . gy is an integer indicating the pupil s likely vertical position within the image . All of these values can be None if they could not be obtained .
def _process_eye_image(eyeimg, pupthreshold=50, glintthreshold=200, \
	glint=True, mode='diameter', debugindex=None):
	
	"""Finds the pupil and the glint in a single image of an eye, and
	returns the relevant parameters. Parameters that cannot be found
	will be None.
	
	Arguments
	
	eyeimg		-	A numpy.ndarray with unsigned, 8-bit
					integers that reflect the greyscale values
					of what is assumed to be an eye.
	
	Keyword Arguments
	
	glint			-	A Boolean that indicates whether the glint
					(the corneal reflection) should also be
					detected. Default = True.
	
	mode			-	A string that indicates how the pupil size
					should be reported.
					'diameter' reports the width of the rect in
					which the thresholded pupil fits
	
	Returns
	[px, py, ps, gx, gy]
				-	px is an integer indicating the pupil's
					likely horizontal position within the image.
					py is an integer indicating the pupil's
					likely vertical position within the image.
					ps is an integer indicating the pupil's
					size in pixels. The size reflects the width
					of the rect in which the pupil falls when
					mode=='diameter', or the total amount of
					thresholded pixels when mode'surface'.
					gx is an integer indicating the pupil's
					likely horizontal position within the image.
					gy is an integer indicating the pupil's
					likely vertical position within the image.
					All of these values can be None if they
					could not be obtained.
	"""
	
	# Create masks using the pupil (dark) and glint (light) luminance
	# thresholds.
	mask = {'p':eyeimg < pupthreshold}
	if glint:
		# Create a mask using the pupil luminance threshold.
		mask['g'] = eyeimg > glintthreshold
	
	# Go through both masks, and save the extracted values.
	v = {'px':None, 'py':None, 'ps':None, 'gx':None, 'gy':None}
	for m in mask.keys():

		# Get connected components. The first component (comp==0) is
		# the background, and the others are connected components
		# without an ordering that's useful to us. The pupil will be
		# the largest component, so we will need to find that.
		comp, ncomp = ndimage.label(mask[m])

		# In DEBUG mode, draw the thresholded components.
		if _DEBUG and m == 'p':
			# Display the components in the central top/bottom pane.
			_AX[debugindex][1].imshow(comp, cmap='jet')
			_AX[debugindex][1].set_title("dark components")
		
		# Only proceed if there is more than one connected component
		# (if there is only one, that's just the background).
		if ncomp > 1:
			# Find the largest component (we assume this is the
			# pupil).
			pupcomp = 1
			compsum = 0
			for i in range(1, ncomp+1):
				s = numpy.sum(comp==i)
				if s >= compsum:
					compsum = s
					pupcomp = i
			# Fill in the gaps in the imperfect thresholding, to
			# better estimate the pupil area.
			pup = ndimage.binary_closing(comp==pupcomp).astype(int)
			# Get all points that are within the pupil as (y,x)
			# coordinates.
			coords = numpy.column_stack(numpy.nonzero(pup))
			# Extra check to see whether there are two or more
			# coordinates.
			if coords.shape[0] > 1:
				# Find the rect that encapsulates the pupil.
				x, y = coords[:,1].min(), coords[:,0].min()
				v['%ss' % (m)], h = coords[:,1].max() - x, \
					coords[:,0].max() - y
				v['%sx' % (m)] = x + v['%ss' % (m)]/2
				v['%sy' % (m)] = y + h/2
				# If required, calculate the pupil surface.
				if m == 'p' and mode == 'surface':
					v['%ss' % (m)] = numpy.sum(pup)

				# In DEBUG mode, colour the detected pupil, and draw a
				# draw a frame around it.
				if _DEBUG and m == 'p':
					# Create an RGB image from the grey image.
					img = numpy.dstack([eyeimg,eyeimg,eyeimg])
					# Colour the thresholded pupil blue.
					img[:,:,0][pup==1] = img[:,:,0][pup==1]/2
					img[:,:,1][pup==1] = img[:,:,1][pup==1]/2
					img[:,:,2][pup==1] = img[:,:,2][pup==1]/2 + 255/2
					# Display the detected pupil in the right
					# top/bottom pane. (Only when the glint is not
					# to be marked.)
					if not glint:
						_AX[debugindex][2].imshow(img)
						_AX[debugindex][2].set_title("detected pupil")
						# Draw a green rectangle around the pupil.
						_AX[debugindex][2].add_patch(patches.Rectangle( \
							(x-1, y-1), v['ps']+2, h+2, \
							edgecolor=(0,1,0), fill=False, linewidth=1))
				# In DEBUG mode, colour the detected glint, and draw a
				# draw a frame around it.
				if _DEBUG and glint and m == 'g':
					# Colour the thresholded glint red.
					img[:,:,0][pup==1] = img[:,:,0][pup==1]/2 + 255/2
					img[:,:,1][pup==1] = img[:,:,1][pup==1]/2
					img[:,:,2][pup==1] = img[:,:,2][pup==1]/2
					# Display the detected pupil and glint in the
					# right top/bottom pane.
					_AX[debugindex][2].imshow(img)
					_AX[debugindex][2].set_title("detected pupil")
					# Draw a green rectangle around the pupil.
					_AX[debugindex][2].add_patch(patches.Rectangle( \
						(v['px']-v['ps']/2-1, v['py']-v['ps']/2-1), \
						v['ps']+2, v['ps']+2, edgecolor=(0,1,0),
						fill=False, linewidth=1))
	
	return v['px'], v['py'], v['ps'], v['gx'], v['gy']
def _process_eye_image ( eyeimg , pupthreshold = 50 , glintthreshold = 200 , glint = True , mode = 'diameter' , debugindex = None ) : # Create masks using the pupil (dark) and glint (light) luminance # thresholds. mask = { 'p' : eyeimg < pupthreshold } if glint : # Create a mask using the pupil luminance threshold. mask [ 'g' ] = eyeimg > glintthreshold # Go through both masks, and save the extracted values. v = { 'px' : None , 'py' : None , 'ps' : None , 'gx' : None , 'gy' : None } for m in mask . keys ( ) : # Get connected components. The first component (comp==0) is # the background, and the others are connected components # without an ordering that's useful to us. The pupil will be # the largest component, so we will need to find that. comp , ncomp = ndimage . label ( mask [ m ] ) # In DEBUG mode, draw the thresholded components. if _DEBUG and m == 'p' : # Display the components in the central top/bottom pane. _AX [ debugindex ] [ 1 ] . imshow ( comp , cmap = 'jet' ) _AX [ debugindex ] [ 1 ] . set_title ( "dark components" ) # Only proceed if there is more than one connected component # (if there is only one, that's just the background). if ncomp > 1 : # Find the largest component (we assume this is the # pupil). pupcomp = 1 compsum = 0 for i in range ( 1 , ncomp + 1 ) : s = numpy . sum ( comp == i ) if s >= compsum : compsum = s pupcomp = i # Fill in the gaps in the imperfect thresholding, to # better estimate the pupil area. pup = ndimage . binary_closing ( comp == pupcomp ) . astype ( int ) # Get all points that are within the pupil as (y,x) # coordinates. coords = numpy . column_stack ( numpy . nonzero ( pup ) ) # Extra check to see whether there are two or more # coordinates. if coords . shape [ 0 ] > 1 : # Find the rect that encapsulates the pupil. x , y = coords [ : , 1 ] . min ( ) , coords [ : , 0 ] . min ( ) v [ '%ss' % ( m ) ] , h = coords [ : , 1 ] . max ( ) - x , coords [ : , 0 ] . max ( ) - y v [ '%sx' % ( m ) ] = x + v [ '%ss' % ( m ) ] / 2 v [ '%sy' % ( m ) ] = y + h / 2 # If required, calculate the pupil surface. if m == 'p' and mode == 'surface' : v [ '%ss' % ( m ) ] = numpy . sum ( pup ) # In DEBUG mode, colour the detected pupil, and draw a # draw a frame around it. if _DEBUG and m == 'p' : # Create an RGB image from the grey image. img = numpy . dstack ( [ eyeimg , eyeimg , eyeimg ] ) # Colour the thresholded pupil blue. img [ : , : , 0 ] [ pup == 1 ] = img [ : , : , 0 ] [ pup == 1 ] / 2 img [ : , : , 1 ] [ pup == 1 ] = img [ : , : , 1 ] [ pup == 1 ] / 2 img [ : , : , 2 ] [ pup == 1 ] = img [ : , : , 2 ] [ pup == 1 ] / 2 + 255 / 2 # Display the detected pupil in the right # top/bottom pane. (Only when the glint is not # to be marked.) if not glint : _AX [ debugindex ] [ 2 ] . imshow ( img ) _AX [ debugindex ] [ 2 ] . set_title ( "detected pupil" ) # Draw a green rectangle around the pupil. _AX [ debugindex ] [ 2 ] . add_patch ( patches . Rectangle ( ( x - 1 , y - 1 ) , v [ 'ps' ] + 2 , h + 2 , edgecolor = ( 0 , 1 , 0 ) , fill = False , linewidth = 1 ) ) # In DEBUG mode, colour the detected glint, and draw a # draw a frame around it. if _DEBUG and glint and m == 'g' : # Colour the thresholded glint red. img [ : , : , 0 ] [ pup == 1 ] = img [ : , : , 0 ] [ pup == 1 ] / 2 + 255 / 2 img [ : , : , 1 ] [ pup == 1 ] = img [ : , : , 1 ] [ pup == 1 ] / 2 img [ : , : , 2 ] [ pup == 1 ] = img [ : , : , 2 ] [ pup == 1 ] / 2 # Display the detected pupil and glint in the # right top/bottom pane. _AX [ debugindex ] [ 2 ] . imshow ( img ) _AX [ debugindex ] [ 2 ] . set_title ( "detected pupil" ) # Draw a green rectangle around the pupil. _AX [ debugindex ] [ 2 ] . add_patch ( patches . Rectangle ( ( v [ 'px' ] - v [ 'ps' ] / 2 - 1 , v [ 'py' ] - v [ 'ps' ] / 2 - 1 ) , v [ 'ps' ] + 2 , v [ 'ps' ] + 2 , edgecolor = ( 0 , 1 , 0 ) , fill = False , linewidth = 1 ) ) return v [ 'px' ] , v [ 'py' ] , v [ 'ps' ] , v [ 'gx' ] , v [ 'gy' ]