By Paul Fricker, MathWorks
Researchers in fields as diverse as optometry, astronomy, and photonics face a common challenge: how to accurately measure structural deformations in circular optical elements such as ocular lenses or corneas (in optometry), mirrors (in astronomy) or optical fibers (in photonics), or the aberrations in optical wavefronts caused by these deformations.
In optical systems, both the measurement devices, which are constructed using lenses, optical fibers, or other optical components, and the subjects being measured, such as a patient’s eye or a telescope mirror, are often circular. As a result, measurement data is usually expressed over a circular domain. When researchers need to characterize the structure of measured deformations and aberrations using Fourier analysis they most often use Zernike functions because these form a complete, orthogonal basis over the unit circle.
Using pre- and post-operative corneal topography data from a LASIK surgery patient as an example, this article describes the modal analysis of optics data using Zernike functions implemented in MATLAB. The Zernike function M-files used in this article are available for download. Using these M-files, computing the spectrum of Zernike modal amplitudes can be performed with a few simple lines of MATLAB code.
The Zernike functions (Figure 1) are a product of the Zernike radial polynomials and sine- and cosine-functions,
The index n = 0,1,2,… is called the degree of the function or polynomial, while m = -n to +n, with (n-m) even, is called the order. The radial polynomials are usually defined using their series representation as a finite sum of powers of r2:
Although this expression looks complicated, the Rmn(r) are, in fact, simple polynomials (Table 1).
|R02(r)||2r2 – 1|
|R13(r)||3r3 – 2r|
Table 1. The first six Zernike radial polynomials
The first 10 Zernike functions, evaluated using equation 1, are listed in Table 2. The low mode number functions are used so frequently for analyzing optical data that many are given common names.
|Z-22(r,θ)||r2 cos 2θ||astigmatism|
|Z02(r,θ)||2r2 – 1||defocus|
|Z22(r,θ)||r2 sin 2θ||astigmatism|
|Z-33(r,θ)||r3 cos 3θ||trefoil|
|Z-13(r,θ)||(3r3 – 2r) cosθ||coma|
|Z13(r,θ)||(3r3 – 2r) sinθ||coma|
|Z33(r,θ)||r3 sin 3θ||trefoil|
Table 2. The first ten Zernike radial functions and their common names.
These functions are useful as a basis for decomposing complex functions or data because they are orthogonal over the unit circle, meaning that they satisfy the following relation:
The factor (2n + 1)-1 on the right is usually used as a normalization constant for the functions. Using this orthogonality, any function f(r,θ) defined on the circle can be expressed as a sum of Zernike modes, just as sine and cosine functions are used in familiar 1-D Fourier analysis
By representing data in this way we can summarize a complicated structural deformation or aberration in terms of a small number of coefficients associated with the dominant Zernike modes.
The coefficients in Equation 2 are evaluated by inverting the equation,
The anm can be determined directly from this expression if f(r,θ) is a known function, or computed numerically if f is a set of measurement data. In the latter case, the formal approach to computing these integrals is to use a numerical quadrature routine.
In our example, we use a faster and simpler alternative: we analyze the LASIK surgery data by computing approximate coefficients, evaluated by truncating the original summation after a finite number of terms N, and compute the required Zernike functions at the data grid point locations (ri,θi),
This truncation produces an overdetermined system of linear equations in the unknown coefficients ap, which we can solve as a matrix equation using the MATLAB left matrix division operator,
This operator computes the numerical solution to this system in the least squares sense. Since this calculation is essentially a regression analysis, the computed coefficient values depend on the number and nature of the basis functions that we use. Therefore, after completing the analysis we must confirm whether we have used enough Zernike modes to accurately characterize the original data.
The corneal topography data was collected before and after a patient underwent LASIK surgery to correct an astigmatism. The patient has a significant primary corneal astigmatism in each eye (Figure 2). Zernike analysis will enable us to quantify the size of the corneal deformation before surgery and to assess whether the surgery was successful.
We could use any number of Zernike modes to compute the Zernike spectrum. We will use the first 36 modes, which correspond to the full set of functions from n = 0 to n = 7, as this is the set most commonly used in practice.
The number of modes required to accurately characterize the data is dictated by features of the data itself, particularly the amount of fine-scale structure. Once we have decided how many modes to use in the analysis, we can easily assess the quality of the resulting data fit by using the computed Zernike spectrum to reconstruct the data and comparing the reconstruction to the original. However, since the coefficients will be computed using a least squares fitting procedure, we must use all the functions from (n,m) = (0,0) to (n,m) = (7,7) inclusive.
The scanned image data has been resampled onto a 301 x 301 grid to keep the size of the data manageable. The data has been cropped so that the center of the eye is at the center of the data matrix, and the edges of the matrix correspond to the boundary of the pupil.
We begin by creating grid coordinate matrices expressed in polar coordinates.
L = size(eyedata,1);
X = -1:2/(L-1):1;
[x,y] = meshgrid(X);
x = x(:); y = y(:);
[theta,r] = cart2pol(x,y);
Next, we compute the required degree and order values from n = 0 to n = 7, inclusive.
N = ; M = ;
for n = 0:7
N = [N n*ones(1,n+1)];
M = [M -n:2:n];
Finally, using the function
zernfun.m, we compute the required Zernike functions for all grid points within the unit circle using the MATLAB left divide operator “\”.
is_in_circle = ( r <= 1 );
Z = zernfun(N,M,r(is_in_circle),theta(is_in_circle));
a = Z\eyedata(is_in_circle);
Figure 3 shows the computed coefficients.
In addition to the constant offset (Z00), the dominant modes in the data include the astigmatism and defocus (Z±22) and defocus (Z02), the secondary astigmatism (Z±24), and the much higher-order Z06 mode.
To quickly assess the quality of the results, we reconstruct the topology data from the computed Zernike coefficients and compare it to the original.
reconstructed = NaN(size(eyedata));
reconstructed(is_in_circle) = Z*a;
Qualitatively, the agreement between the original and the reconstructed data is very good (Figure 4).
Numerically, we can estimate the quality of the fit by calculating the absolute difference between the original and derived data sets and normalizing by the maximum difference value (Figure 5).
The post-LASIK-surgery corneal topography data for the patient’s left eye is shown in Figure 6.
Clearly, the surgery has removed most of the corneal deformation observed in the original data. To quantify the improvement, we compute the Zernike spectrum using exactly the same procedure that we used on the pre-surgery data.
Figure 7 shows that the large amplitudes associated with the primary and secondary astigmatisms have been eliminated.
Overall, the amplitudes in the post-operative data are smaller than those in the pre-operative data. Any remaining small modal amplitudes are caused by remnants of the original deformation around the perimeter of the affected area. Fortunately, these ridges are very small and are away from the central axis of the eye.
The example in this article demonstrates how practitioners, physicians, and medical researchers can use MATLAB to investigate the structure and important features of their measured aberration and deformation data. The numerical analysis techniques described in this article can be used in all fields of optics, from astronomy to photonics, to medical optics. For optical scientists and engineers who want greater control over the manipulation of their data or who need to perform custom analyses not provided by their measurement instruments, MATLAB is an ideal tool for developing an efficient, robust implementation of optics functionality like the Zernikes, and for using these tools to characterize their data.
The Zernike function M-files used in this article are available for download.
Frederik (Frits) Zernike was born in Amsterdam on July 16, 1888. He graduated with a doctorate in chemistry from the University of Amsterdam in 1915. That same year, Zernike became a lecturer in physics at the University of Groningen, becoming a full professor in 1920.
For the next decade, Zernicke focused his research on statistical mechanics, turning to optics in the 1930s. He invented phase contrast microscopy, a technique that exploits the phase differences produced by different materials or tissues when diffracting light. These phase differences, which cause changes in intensity, can be used to image living tissue without using dyes or stains.
Zernike received a patent for this invention in 1936, and was awarded the Nobel Prize in 1953 He received numerous other awards and honors, including an honorary doctorate in Medicine from the University of Amsterdam, and the Rumford Medal from the Royal Society in 1952. He became a Fellow of the Royal Society in 1956.
Zernike functions, denoted Zmn(r,θ), are an infinite set of orthogonal functions defined on the unit circle r Ε [0,1], θ Ε [0,2p]. Because of their orthogonality, and because the set of Zernikes provides a function for every allowed (n,m)-pair, they are the most commonly used basis for performing modal analyses of optics data.
Astigmatism is an abnormal curvature in the shape of the cornea or lens, usually due to an ellipsoidal or egg-shaped distortion of the eye. This deformation blurs the vision because it prevents light rays entering the eye at different locations from meeting at the correct point.
LASIK surgery (laser-assisted in situ keratomileusis) corrects the shape of the eye by removing thin layers of tissue from the corneal stroma, the thick middle layer of the cornea.
Corneal topography measurements are used before surgery to identify the amount of corrective reshaping that must be performed.
Paul Fricker is a MathWorks Principal Consulting Engineer. Paul has more than 15 years’ experience in signal and image processing, modeling and simulation, and application development. He holds a B.Sc. in Chemistry from Dalhousie University, an M.Sc. in Physics from the University of Toronto, and a Ph.D. in Civil Engineering from Massachusetts Institute of Technology.
Published 2008 - 91544v00