Real-time Pupil Detection based on Contour Tracking

Abstract: A new method for pupil detection was proposed on the basis of contour tracking in this paper. The method scans the binary pupil image to find the starting point of the contour, and then find the complete contour from the starting point. Calculate the contour area to judge if it is eyelash or pupil area. Continue to search until the pupil contour is found and then calculate its diameter and center. According to the pupil information of the previous frame, narrow the detection region for binaryzation and track the contour to get the pupil information of the current frame. Threshold for binarization can be fixed, which is the threshold of the first frame of the cropped image. Experimental results show that the method has high accuracy, stable performance, and can meet the real-time detection speed.


Introduction
Human pupil diameter changes from 2mm to 8mm in general.Regardless of its shape, margin and reflection, pupil has important academic and clinical research value in the human visual system because of its special sensitivity.Therefore, pupil detection is often used for clinical diagnosis [1].Real-time pupil detection and tracking is an important research topic in the field of computer vision, and is related to many subjects such as physiology, artificial intelligence, pattern recognition, computer vision, image analysis and processing.Meanwhile, it has huge potential application value in the field of health care, traffic security [2], public security guarantee, military affairs, criminal investigation and so on.
Currently, manual inspection is mainly used for the detection of the pupil size, only can give positive diagnosis of the patients with dramatic symptoms.Missed diagnosis of mild symptoms will lead to missed treatment opportunities.If we can detect the above indicators objectively and quantitatively, small changes will be found in the early stage of the disease and postoperative monitoring for timely treatment, and will save more physiological function of patients.
As a part of the iris recognition detection, the current commonly used pupil localization methods are circular detection operator proposed by Daugman [3] and binarization combined with Hough transform proposed by Wildes [4].The calculus algorithm proposed by Daugman has high accuracy and robustness, but has long detection time due to the blind search, resulting in a waste of computation.Wildes's algorithm has been improved in the localization speed, but also has the problem of long computation time.Then in order to improve the speed and precision of the Hough transform, the scholars put forward the improved algorithm of Hough transform, such as the point Hough transform [5,6].These methods are based on circle detection, so the least square method is used to fit the ellipse when pupil is not perfect circle [7].In addition, other people put forward methods like morphological reconstruction [8], template matching [9], regional growth [10] for pupil detection and pupil extraction based on image feature [11].
This paper realized real-time detection for pupil parameters under light stimulation, mainly using contour tracking to locate the pupil.As the contour tracking has nothing to do with the pupil shape, it is applicable to the irregular pupil.The scope of application can be wider.

Contour tracking method
Contour tracking, also called boundary tracking, is a method used to extract the boundary information in digital images, which can be used in the segmentation of gray images or binary images.So far, scholars have proposed a variety of contour tracking and other improved methods.Square tracking method, Moore neighborhood tracking method, radial scan method, Theo Pavlidis method and so on are comparatively classical [12].Each method has its own advantages and defects, and can not apply to all the image conditions.
The basic steps of contour tracking methods are as following: Firstly, determine a point on the object contour as starting point according to some criterions; secondly, find new boundary points in turn from the starting point according to the criteria of tracking; finally, stop tracking according to the conditions for termination.If the image has more than one connected boundary, repeat tracking steps to search for new contours.

Pupil Imaging
Infrared light is generally used in pupil detection.Near-infrared spectrum between 850nm and 950nm has no stimulation to human eyes, and the retina can reflect the incident light up to eighty or ninety percent.The edge between pupil and iris can be very clear, so the part of the pupil is highlighted.However, there is an unavoidable interference of light source and eyelash in pupil images.Figure 1 shows the pupil image of 450*275 pixels acquired under the illumination of 850nm infrared.

Image Binarization
In pupil detection, the aim of binarization is to divide the pupil image into two parts, the pupil and the background.The key is to find the appropriate threshold.As a commonly used method in image processing, a variety of binarization methods have been proposed up to now, such as Otsu method, optimal interactive threshold method, global threshold method based on minimum error and so on.For pupil images, these methods can not be used to segment the pupil perfectly.According to the characteristics of pupil images, binarization based on the histogram is used to find the appropriate threshold.
As shown in Figure 1, the gray value of the pupil part in infrared image is significantly lower than the other parts.The large difference between the pupil and the background will form two peaks on the histogram.As shown in Figure 3, pupil region is located around the first peak and the background is located around the second peak.Setting the corresponding gray level of trough between two peaks as the threshold can separate the pupil from the background as much as possible.Choose the gray level of the trough right to the first peak as threshold for binarization, the result is shown in Figure 4.

Eyelash Removal and Contour Tracking
As the light spot falls inside the pupil, contour tracking of the outer boundary of the pupil will not affect the integrity of the pupil, thus will not affect the calculation of pupil size, center and diameter.However, due to the gray level of eyelash and pupil are close, not only pupil but also eyelash are existed in the binary image.Only avoid the eyelashes can find the real pupil contour.In pupil detection, the morphological methods such as erosion and dilation are used to preprocess the pupil gray image [10], and then after binarization the eyelashes can be removed.However, this method will greatly reduce the calculation speed, and may cause the distortion of the pupil's edge easily.Therefore, eyelashes will be removed in the process of contour tracking in this paper.
The pupil image is approximately circular, and it is a complete connected domain, which will not be cut off or 8-connected.So simple and fast tracking method is enough to meet the requirement.Firstly, find the first boundary pixels: Search from top to bottom, left to right.Every time meet a black pixel, search its 8 neighborhood.If the number of black pixels in 8 neighborhood is greater than or equal to 3, confirm that it is not isolated noise, but the starting point of the first boundary.Secondly, search for the neighboring boundary points from the starting point: Define the initial search direction along the top right.If the top right point is black, it is the new boundary point, otherwise the search direction rotate 45 degrees clockwise until the first black pixel is found.Then set the black pixel as the new boundary point, rotate 90°counterclockwise based on the current search direction.Continue to search for the next black pixel with the same approach.Finally, when the initial boundary point is found, once contour tracking ends.The contour tracking process is shown in Figure 5.
Due to the binary image of pupil has a few eyelash noise located above the pupil, although the isolated noise have been skipped while looking for the first boundary pixel, the first boundary be tracked may also be large eyelash region.Therefore, calculate the area surrounded by the contour, if less than a certain value, it is not regarded as the pupil, continue to look for new contours, until the pupil contour is found.For the images processed in this paper, the value can be 1500.The contour tracking process of this paper is shown in Figure 6.
After the contour tracking of binary image, store the contour points of the pupil in an array, and finally calculate the center and diameter of the pupil.

Calculation of Pupil Information
According to the contour array got by contour tracking, add up the number of points surrounded by pupil contour as the pupil area.Then calculate the radius of the pupil according to the the formula of circle area.The center of the pupil is calculated by the formula of mass center: In the formula, x and y are the horizontal and vertical coordinates of the pupil center, and ij x and ij y are the horizontal and vertical coordinates of the pupil pixels respectively, n is the number of pupil points.

Simplification of method 4.1 Narrow the Search Range
Pupil is only a part of eye, in the process of localization, if the approximate location of the pupil is known according to a priori knowledge, you can narrow the search range to improve the detection rate further.Some papers use gray projection method [13] in pupil detection for coarse positioning on the pupil.However, if illumination is uneven and image range is large, the overall gray value of the tail side of the eye is low relatively, gray projection in the column direction will be impacted, thus resulting errors in the coarse positioning.
As in the acquisition process of images, the pupil will not move casually, the pupil position of two adjacent frames are basically the same.After calculation to the previous frame for the information of pupil, Set the pupil center as the new center of the current frame, cut area of 160*160 pixels as shown in Figure 7. Operate binarization and contour tracking on the narrowed area in the square to get the pupil information of this frame.Then repeat operation to the next frame according to this pupil center until all the images are tested.Narrowing the search scope can greatly reduce the amount of computation and speed up the detection rate.

Using Fixed Threshold
As the acquisition of pupil images is under the dark condition, environment changes little, set the threshold of the first narrowed frame as the fixed threshold can also reduce the computation and speed up the detection rate.

Experiment results
In order to verify the effectiveness and real-time of the method, 600 images aquired continuously are processed.The pupil image is 450*275 pixels, 8-bit gray.Experiment is under the hardware environment of i5 CPU, 4GB memory, 64-bit operating system and software environment of VS2008 in C++ language.
Compare three methods of Hough transform, regional growth method in literature [10] and this paper.Table 1 shows the positioning results of these three methods.It can be seen that the pupil center and the diameter of these methods are basically consistent.However, as the pupil is not a perfect circle, pupil positioning of Hough transform vary slightly.Process the images acquired continuously.As the diameters calculated by Hough transform are statistical results, and if deviation between the pupil shape and the perfect circle is great, the error of pupil centers and diameters detected will be large, so do the curve.Region growing method and the method of this paper do not need to take into account the pupil shape, the results are close and the curves are smooth.
The changes of pupil diameters under flash stimulation of three methods are shown in Figure 8. Statistics of running time of three methods shown that Hough transform has large amount of computation, so it is longest; literature [10] increases the operation time due to the use of dilation and erosion; the proposed method is fastest, the more images are detected, the more obvious advantages are, shown in Table 2.The results show that the proposed method can meet the requirements of real-time pupil detection.

Conclusion
A new method for pupil detection was proposed on the basis of contour tracking in this paper to locate pupil center.The effect of isolated noise and eyelashes are removed in the process of contour tracking.In the method, reduce the processing range according to the initial image and set the threshold of the first frame of the reduced image as the fixed threshold for subsequent treatment.The method can speed up the image processing rate of pupil detection on the basis of accurate location of the pupil center and can finally meet the requirements of real-time pupil detection.Because it is suitable for the detection of irregular pupil, it can be applied to the objective and quantitative detection of some eye diseases.

Figure 3 .
Figure 3. Histogram of pupil image

Figure 4 .
Figure 4. Binary Image of pupil image

Figure 8 .
Figure 8. Pupil diameter curves of three methods

Tabble 1 .
Location results of three methods

Table 2 .
Comparison of method efficiency