Estimation of centroid positions with a matched-ﬁlter algorithm: relevance for aberrometry of the eye

: Most Shack-Hartmann based aberrometers use infrared light, for the comfort of the patients. A large amount of the light that is scattered from the retinal layers is recorded by the detector as background, from which it is not trivial to estimate the centroid of the Shack-Hartmann spot. For a centroiding algorithm, background light can lead to a systematic bias of the centroid positions towards the centre of the software window. We implement a matched ﬁlter algorithm for the estimation of the centroid positions of the Shack-Hartmann spots recorded by our aberrometer. We brieﬂy present the performance of our algorithm, and recall the well-known robustness of the matched ﬁlter algorithm to background light. Using data collected on 5 human eyes, we parameterise a simple and fast centroiding algorithm and reduce the difference between the two algorithms down to a mean residual wavefront of 0.02 µ m rms.


Introduction
The Shack-Hartmann wavefront sensor has a large number of ophthalmic applications, some of which have a great impact on the future life of the patients. Naturally, its performance has been questioned by many authors, usually for the problem of reconstructing the wavefront map from the measured centroid positions [1][2][3][4][5]. However, the measurement of the centroid positions is the core of the Shack-Hartmann wavefront sensor, and corresponds to the largest reduction of data in the measurement process [6,7].
Aberrometers are usually designed with a large number of CCD pixels per single lenslet, in order to cope with the extended nature of the Shack-Hartmann spots and provide adequate dynamic range. Shack-Hartmann spots are processed independently using a "software window", which typically corresponds to the aperture of one lenslet (between 10 × 10 and 20 × 20 pixels). As result, a large number of noisy pixels do not carry any significant information about the measured wavefront, and are responsible for a lack of precision in the estimation of the centroid positions.
The noise that corrupts the CCD data recorded by a Shack-Hartmann wavefront sensor is classically described by combined Poisson and Gaussian statistics, in order to model the fundamental randomness of the detection and the processing of photoelectrons [8]. For an open-loop aberrometer, both the precision and the accuracy of the estimated centroid positions are of primary interest. Precision is usually improved by an adequate reduction of the CCD data, so that noisy CCD pixels are partially suppressed. Methods to suppress irrelevant pixels mainly consist of applying a rectangular or Gaussian weighting function [9][10][11][12][13][14][15] and/or thresholding the data [16][17][18]. These methods can bias the estimated centroid positions if significant information is thrown away [19][20][21][22][23].
Matched filter algorithms have been introduced for solar adaptive optics [24], an application of the Shack-Hartmann wavefront sensor for which no point source is available. They allow to track the spatial features of an extended object, which is imaged by each lenslet of the Shack-Hartmann. For the estimation of the centroid position of a Gaussian Shack-Hartmann spot, a matched filter algorithm has also the advantage of being more linear than a simple centroiding [23,25].
Near infrared light is commonly used for aberrometry in the eye [26], at the cost of an increased amount of scattered background in the recorded CCD data. The major consequence of the background light on a centroiding algorithm is to bias the estimated centroid position towards the centre of the software window, simply because of its uniform distribution across the detector plane. We show in the next section that this feature is of particular relevance for aberrometry of the eye. As an alternative, we stress the benefit of estimating the centroid position of the Shack-Hartmann spot with a matched filter algorithm. The linearity of the matched filter algorithm is insensitive to the amount of background light, when the cross correlation is computed with Fourier transforms [27].

Description of the custom-built aberrometer
We present in this section some numerical simulations of the performance of a matched filter and a centroiding algorithms. We parameterise our simulations to realistically model the measurement process of a custom-built aberrometer, which we present in Fig. 1. The 0.2 mm pitch of a lenslet corresponds to 18.5 pixels of the CCD, and the data are processed using 15 × 15 software windows. The aberrometer uses a very narrow probing beam of full width at half maximum (FWHM) 0.5 mm in the pupil of the eye, in order to consistently obtain Gaussian Shack-Hartmann spots of FWHM w 3.5 pixels. We typically use a 15 µW probing beam to obtain spots with a mean peak a 400 D.U., at a 100 Hz frame rate. The detector has a 40 e − rms readout noise, and a gain of 30 e − /D.U. The use of a scanning mirror, which is conjugated with the pupil of the eye, reduces drastically the speckled aspect of the spots due to scattering [28]. For a mean signal a 400 D.U., we experimentally evaluated the precision of the centroid positions estimated with a matched filter algorithm as a standard deviation of 0.006 pixels. To do so, we measured a sequence of 1000 wavefronts using an artificial eye (a 18 mm lens, with an opaque screen in the back focal plane) in a "double-pass" configuration. This random error corresponds to a 2.5 nanometers rms error on the estimated wavefronts. We summarise the main parameters of our custom-built aberrometer in Table 1.

Parameterisation of the simulations
We model the 15 × 15 noise-free CCD image recorded by our custom-built aberrometer as a Gaussian profile with an additional homogeneous background. The FWHM of the simulated Shack-Hartmann spot is w = 3.5 pixels, the peak signal is a = 400 (10 bit) Digital Unit (D.U.), and the background b = 50 D.U. These values are typical for our aberrometer, operating at 780 nm. The centroid position of the spot is parameterised by the 2-dimensional vector ρ ρ ρ (in pixels, with the centre of the software window taken as origin). Only shifts smaller than 0.5 pixels are considered, which corresponds to accurately positioned software windows ("second pass centroiding"). We model the noise of each CCD pixel independently, as combined Poisson and Gaussian statistics, parameterised by the gain and the readout noise of the camera. (See Table 2.)

Matched filter algorithm
The matched filter algorithm estimates the shift that maximises the scalar product of a reference image (Gaussian spot, of FWHM 3.5 pixels) with the recorded data [8]. The scalar product of the two images can be seen as a cross correlation and thus be computed using the Fourier transform, according to the correlation theorem [23,27,29]. The linearity of the algorithm can be understood with the Shannon sampling theorem and the concept of space-bandwidth product [30]. The algorithm that we implemented is described in [27]. The accuracy of the estimated shift of the spot depends on the interpolation of the cross correlation. We do this interpolation by padding the cross spectrum of the two functions with zeroes, so that the estimated cross correlation has a size of 45 × 45 pixels.
The amount of shift that can be estimated without noticeable bias depends on the FWHM of both images. The accuracy of the algorithm is better than 0.001 pixels in the absence of noise for spots of FWHM w = 3.5 pixels shifted up to ρ x = 4 pixels, independent of the amount of homogenous background.

Centroiding algorithm
The matched filter is compared in this paper with a centroiding algorithm that uses a rectangular window, of width R (in pixels), and a normalised threshold 0 ≤ t ≤ 1. The algorithm first computes the minimum b and the maximum a of the 15 × 15 local data, and then set to zero the data that are bellow the threshold value (2a/3 − b) × t + b. A rectangular windowing is then applied, and the center of mass is computed as an estimate of the centroid position. The algorithm is shown in Fig. 2. For t = 0, there is no effective thresholding of the data. For t = 1, the threshold level is 2a/3. a (10 bit) D.U.
Parameterisation of a centroiding algorithm, with a normalised threshold t and a rectangular window of size R. The gray area corresponds to the data set to zero before centroiding.

Effect of background light on the centroid estimates
The main effect of background light on a centroiding algorithm is to introduce non-linearity in the estimated centroid positions. As soon as the "true" centroid position (that we define with the noise-free simulation) moves away from the centre of the software window, the centroiding algorithm leads to a biased estimation of the centroid position towards the centre of the window. Without background light, a centroiding algorithm has a given range of linearity, which corresponds to the domain of true centroid positions for which there is no truncation of the Shack-Hartmann spots by the weighting function.
We illustrate this effect with numerical simulations. An ensemble of 1000 noise realizations is simulated for each noise-free Gaussian spot, which is parameterised by a variable centroid position ρ ρ ρ = [ρ x , 0] and the numerical values of Table 2. Fig. 3 shows the Mean Square Error [8] (MSE, in pixels squared) in the estimated x-position of the centroid ( ρ x ) as a function of the noise-free centroid (ρ x ), using two unthresholded (t = 0) centroiding algorithms (R = 5 and R = 15) and the matched filter algorithm.  For the R = 15 algorithm, this effect is due to the contribution of the uniform background light, the centroid of which is in the middle of the processed window. As a result, the estimated position of the centroid is biased towards zero. Without background light, the R = 15 centroiding algorithm remains linear (blue solid graph), because there is no significant truncation of the Gaussian spot over the full [0 − 0.5] pixels range of shifts.
The R = 5 centroiding algorithm is not linear both with and without background light (red dotted and solid graphs respectively), because there is a significant truncation of the Shack-Hartmann spot by the 5 × 5 rectangular window. For ρ x = 0.5, the error is 0.17 pixels without background, and 0.27 pixels with background. With background light, the error arises from a combined effect of the truncation of the Shack-Hartmann spot and the background. In the zero shift case (ρ x = 0), the low MSE error of the R = 5 centroiding algorithm (MSE 2 × 10 −5 pixels squared, both with and without background) should be carefully interpreted. This is a typical feature of a biased estimator, which can perform better than the theoretical lower bound of the variance [23]. This so called Cramér-Rao lower bound [8] has been investigated for the estimation of the centroid position of a point source [31,32], which is of particular relevance for the Shack-Hartmann wavefront sensor.
The matched filter remains linear over the whole [0-0.5] pixels range of shifts, even with the background light. The MSE of the matched filter is higher with the background light, because it is subject to the combined Poisson and Gaussian noise. For a non-biased estimator, having a larger error (variance) when the contrast of the image decreases is "natural".  Figure 3 thus demonstrates that great caution is required in using a centroiding algorithm in practice, even when "smart" centroiding (recursive variable threshold, variable width centroiding) is used. Taking the matched filter as a reference, we discuss in Section 3 the performance of the centroiding algorithm, for data recorded on 5 human eyes. The comparative study of Section 3 confirms the large non-linearity of the unthresholded centroiding algorithm in the presence of background light. We also quantify the effect of the normalised threshold t on the centroid positions estimated by the centroiding algorithm.

Methodology
We present in this section a comparative study of the matched filter and the centroiding algorithms, using experimental data obtained with our custom-built aberrometer. We measure 5 young subjects during a 1 second trial that has no occurrence of blinks, and we compute the difference ∆ ∆ ∆ρ ρ ρ = ρ ρ ρ cent − ρ ρ ρ m f between the centroid positions estimated by the matched filter ρ ρ ρ m f and the centroiding algorithm ρ ρ ρ cent . The centroiding algorithm uses a threshold t and a rectangular window of size R, which is positioned on the integer value of the centroid position ρ ρ ρ m f . We present in Table 3 the mean values of the peak a and the background b of the data, which are estimated for each subject by spatio-temporal averaging of the minimum and maximum values of the processed local data. The values presented in Table 3 are close to the values we used in the simulations of Section 2 (a = 400 D.U. and b = 50 D.U.). We record more background light on subject 1 than on the other subjects, and we interpret this result by the low pigmentation of his eyes.  Figure 4 shows that, for subject 2, the centroid positions ρ ρ ρ cent ("·") are systematically biased towards the centre of the software window, for R = 9 and no thresholding (t = 0). This effect is also apparent in Fig. 5, which shows that the norm of ∆ ∆ ∆ρ ρ ρ is proportional to the norm of the centroid positions ρ ρ ρ m f . The larger departures from a straight line obtained for the R = 15 centroiding algorithm (right graph of Fig. 5) are due to the contribution of a larger number of noisy pixels. Without any thresholding applied, the centroiding algorithm is barely sensitive to a sub-pixel shift of the Shack-Hartmann spot, for any size R of software window.   and is significant for both subjects 1 and 2. The threshold level t has thus to be set sufficiently high to eliminate completely the background of the local data. Figure 7 shows the partially thresholded CCD data obtained with subject 2, for t = 0.1 (left) and t = 0.2 (middle). In both images, the pixels that are set to zero are not symmetrically distributed around the core of the spot. This leads to a large bias in the centroid estimates. For both subjects 1 and 2, the error is close to a minimum value for t = 0.8, independent of the size of the centroiding window R. For subject 2, σ is relatively insensitive to the value of the threshold in the range 0.4 < t < 0.8. We interpret the difference between the results of subject 1 and 2 by the high amount of background light recorded on subject 1. Given the results of Fig. 6, we will consider in the following the effect of thresholding the data for all subjects, with t = 0.8.

Effect of thresholding
Thresholding reduces the residual error of the centroiding algorithm, from approximatively σ 0.3 pixels (t = 0) down to σ 0.13 pixels (t = 0.8). The residual error does not fall bellow 0.13 pixels. We interpret this residual error by the truncation of the spot, which leads to bias in the centroid estimates. The truncation is illustrated in Fig. 7 (right graph, obtained with a threshold level t = 0.6). Regardless of t, the residual error is well above the 0.006 pixels precision of our aberrometer, which we experimentally measured using an artificial eye. Figure  8 shows for 5 subjects the mean rms error of the tip/tilt removed residual wavefront, for t = 0 and t = 0.8. This residual rms is computed using a modal reconstruction of Zernike coefficients (up to the tenth radial order). A t = 0.8 threshold allows to consistently decrease the difference between the matched filter and the centroiding algorithm down to a mean error of 0.02 µm rms, for the 3 window sizes. Without thresholding, we found a mean rms value of 0.045 µm for R = 5 and R = 9, and 0.062 µm for R = 15.    Fig. 6.) For t = 0.6, the threshold is close to optimal, but there is still a σ 0.13 pixels residual error due to the truncation of the spot.

Conclusion
The extended nature of Shack-Hartmann spots and the amount of background light obtained in human eyes justify the choice of the matched filter algorithm for aberrometry. Its close relationship to the least-squares estimator makes it also suitable for dealing efficiently with a larger number of pixels subject to Gaussian readout noise [8].
However, we have shown that the difference between the (tip/tilt removed) estimated aberrations becomes in the order of 0.02 µm rms when an appropriate thresholding of the data is applied before centroiding (t = 0.8), independently of the size of the rectangular window R. This residual error is not significant for most ophthalmic applications of the Shack-Hartmann wavefront sensor, as it corresponds to λ /25 for a 0.5 µm wavelength. Using MATLAB 7.4.0, we found our implementation of the matched filter algorithm 6 times slower than the centroiding algorithm, for the processing of 15 × 15 pixels images. For an adaptive optics system, the modest gain in accuracy obtained with the matched filter algorithm might therefore be obtained at the cost of a reduced bandwidth, unless appropriate parallel processing of the data is implemented (using field programmable gate arrays for instance).
Without thresholding, the centroiding algorithm leads to centroid positions that are systematically estimated at the centre of the software window. With our custom-built aberrometer, we estimated the corresponding (tip-tilt removed) error between 0.045 and 0.062 µm rms.
This research was funded by Science Foundation Ireland under Grant No 07/IN.1/I906.