Zernike Polynomials
• Fitting irregular and non-rotationally symmetric surfaces over a circular region. • Atmospheric Turbulence. • Corneal Topography • Interferometer measurements. • Ocular Aberrometry
Background
• The mathematical functions were originally described by Frits Zernike in 1934. • They were developed to describe the diffracted wavefront in phase contrast imaging. • Zernike won the 1953 Nobel Prize in Physics for developing Phase Contrast Microscopy.
1 Phase Contrast Microscopy
Transparent specimens leave the amplitude of the illumination virtually unchanged, but introduces a change in phase.
Applications
• Typically used to fit a wavefront or surface sag over a circular aperture.
• Astronomy - fitting the wavefront entering a telescope that has been distorted by atmospheric turbulence.
• Diffraction Theory - fitting the wavefront in the exit pupil of a system and using Fourier transform properties to determine the Point Spread Function. Source: http://salzgeber.at/astro/moon/seeing.html
2 Applications
• Ophthalmic Optics - fitting corneal topography and ocular wavefront data.
• Optical Testing - fitting reflected and transmitted wavefront data measured interferometically.
Surface Fitting
• Reoccurring Theme: Fitting a complex, non-rotationally symmetric surfaces (phase fronts) over a circular domain.
• Possible goals of fitting a surface: – Exact fit to measured data points? – Minimize “Error” between fit and data points? – Extract Features from the data?
3 1D Curve Fitting
25
20
15
10
5
0 -0.1 0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5
Low-order Polynomial Fit
25 y = 9.9146x + 2.3839 R2 = 0.9383 20
15
10
5
0 -0.1 0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5
In this case, the error is the vertical distance between the line and the data point. The sum of the squares of the error is minimized.
4 High-order Polynomial Fit
180025
1600
140020 1200
1000 15 800
600 10 400
200 5 0 -0.1 0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5 -200 0 -0.1-400 0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5
2 16 y = a0 + a1x + a2x + … a16x
Cubic Splines
25
20
15
10
5
0 -0.1 0.1 0.3 0.5 0.7 0.9 1.1 1.3 1.5
Piecewise definition of the function.
5 Fitting Issues
• Know your data. Too many terms in the fit can be numerically unstable and/or fit noise in the data. Too few terms may miss real trends in the surface. • Typically want “nice” properties for the fitting function such as smooth surfaces with continuous derivatives. For example, cubic splines have continuous first and second derivatives. • Typically want to represent many data points with just a few terms of a fit. This gives compression of the data, but leaves some residual error. For example, the line fit represents 16 data points with two numbers: a slope and an intercept.
Why Zernikes?
• Zernike polynomials have nice mathematical properties. – They are orthogonal over the continuous unit circle. – All their derivatives are continuous. – They efficiently represent common errors (e.g. coma, spherical aberration) seen in optics. – They form a complete set, meaning that they can represent arbitrarily complex continuous surfaces given enough terms.
6 Orthogonal Functions
• Orthogonal functions are sets of surfaces which have some nice mathematical properties for surface fitting. • These functions satisfy the property
⎧C i = j V (x, y)V (x, y)dxdy = j ∫∫ i j ⎨ A ⎩ 0 Otherwise
where Cj is a constant for a given j
Orthogonality and Expansion Coefficients
Linear Expansion W(x, y) = ∑a iVi (x, y) i
W(x, y)Vj (x, y) = ∑aiVi (x, y)Vj (x, y) i W(x, y)V (x, y)dxdy = a V (x, y)V (x, y)dxdy ∫∫ j ∑ i ∫∫ i j A i A
1 a = W(x, y)V (x, y)dxdy j ∫∫ j C j A
7 Orthogonality - 1D Example Consider the integral 2π ∫sin()(mx cos m'x )dx where m and m' are integers 0 1 2π = ∫[]sin()()m + m' x + sin m − m' x dx 2 0 x=2π 1 ⎡cos(m + m')x cos(m − m')x ⎤ = − ⎢ + ⎥ 2 ⎣ m + m' m − m' ⎦ x=0
= 0
Orthogonality - 1D Example Two sine terms 2π ∫sin()(mx sin m'x )dx where m and m' are integers 0 1 2π = − ∫[]cos()()m + m' x − cos m − m' x dx 2 0 x=2π 1 ⎡sin(m + m')x sin(m − m')x ⎤ = − ⎢ − ⎥ 2 ⎣ m + m' m − m' ⎦ x=0
= 0 if m ≠ m’ !!!
8 Orthogonality - 1D Example Two sine terms with m = m’ 2π ∫sin()(mx sin m'x )dx where m and m' are integers 0 2π = ∫sin 2 ()mx dx 0 x=2π ⎡x sin(2mx)⎤ = ⎢ − ⎥ ⎣ 2 4m ⎦ x=0
= π Similar arguments for two cosine terms
Orthogonality - 1D Example From the previous arguments, we can define ⎧ ⎛ j ⎞ ⎪ cos⎜ x⎟ ⎪ ⎝ 2 ⎠ j even Vj = ⎨ ⎛ j+1 ⎞ j odd ⎪sin⎜ x⎟ ⎩⎪ ⎝ 2 ⎠
Note that when j = 0, V0 = 1 and
2π 2π V x V x dx= dx= 2π ∫ 0()0 () ∫ 0 0 so the constant Cj = 2π for j = 0, and Cj = π for all other values of j.
9 Orthogonality - 1D Example The functions satisfy the orthogonality condition over [0, 2π]
2π ⎧(1+δ )π i = j V x V x dx= i0 ∫ i ()j () ⎨ 0 ⎩ 0 Otherwise where δ is the Kronecker delta function defined as
⎧1 i = j δij = ⎨ ⎩0 Otherwise
Fit to W(x) = x
j aj 7 0 π 1 -2 6 2 0 5 4 3 -1 W(x) 1 term 3 4 0 3 terms 11 terms 5 -0.6666 2
6 0 1
7 -0.5 0 01234567 8 0 -1 9 -0.4 10 0
10 Extension to Two Dimensions
In many cases, wavefronts take on a complex shape defined over a circular region and we wish to fit this surface to a series of simpler components.
Wavefront Fitting
-0.003 x
= + 0.002 x
+ 0.001 x
11 Unit Circle Divide the real y radial coordinate by the maximum radius to get a normalized coordinate ρ ρ θ 1 x
Orthogonal Functions on the Unit Circle • Taylor polynomials (i.e. 1, x, y, x2, xy, y2,….) are not orthogonal on the unit circle. 2π 1 ⎧C i = j V (ρ,θ)V (ρ,θ)ρdρdθ = j ∫∫ i j ⎨ 0 0 ⎩ 0 Otherwise
where Cj is a constant for a given j Many solutions, but let’s try something with the form
Vi (ρ,θ) = Ri (ρ) Θi (θ)
12 Orthogonal Functions on the Unit Circle • The orthogonality condition separates into the product of two 1D integrals ⎡ 1 ⎤⎡2π ⎤ ⎧C i = j R (ρ)R (ρ)ρdρ Θ (θ) Θ (θ)dθ = j ⎢∫ i j ⎥⎢ ∫ i j ⎥ ⎨ ⎣ 0 ⎦⎣ 0 ⎦ ⎩ 0 Otherwise
This has extra ρ in it, so This looks like the 1D Example, we need different functions so sin(mθ) and cos(mθ) a possibility
ANSI Standard Zernikes
⎪⎧ NmR m (ρ)cosmθ ;for m ≥ 0 Zm (ρ,θ) = n n n ⎨ m m ⎩⎪ − Nn Rn (ρ)sinmθ ;for m < 0
Azimuthal Double Index Component n is radial order Radial m is azimuthal Component frequency Normalization
ANSI Z80.28-2004 Methods for Reporting Optical Aberrations of Eyes.
13 ANSI Standard Zernikes
(n− m )/ 2 s m (−1) (n −s)! n−2s Rn (ρ) = ∑ ρ s=0 s![]0.5(n + m) −s ![]0.5(n − m) −s ! only depends on |m| (i.e. same Constant that depends Powers of ρ for both sine & on n and m cosine terms
The Radial polynomials satisfy the orthogonality equation 1 δ R m (ρ)R m (ρ)ρdρ= nn' ∫ n n' 0 2n+2
ANSI Standard Zernikes
m 2n+2 Nn = 1+δm0
constant that depends on n & m
14 Orthogonality
2π1 ⎧C for n = n';m = m' Zm'(ρ,θ)Zm(ρ,θ)ρdρdθ = n,m ∫∫ n' n ⎨ 0 0 ⎩0 Otherwise
2π⎧ cos(m'θ) ⎫⎧ cos(mθ) ⎫ Nm'Nm dθ n' n ∫⎨ ⎬⎨ ⎬ 0 ⎩sin()−m'θ ⎭⎩sin()−mθ ⎭ 1 ⎧C for n = n';m = m' × Rm'(ρ)Rm(ρ)ρdρ = n,m ∫ n' n ⎨ 0 ⎩0 Otherwise
Orthogonality
m' m ⎡ δn'n ⎤ ⎧Cn,m for n = n';m = m' Nn' Nn []δm'm()1+δm0 π ⎢ ⎥ = ⎨ ⎣2n+2⎦ ⎩0 Otherwise
This equals zero unless m=m’ This equals zero So this portion is unless n=n’ satisfied
What happens when n=n’ and m=m’?
15 Orthogonality When n=n’ and m=m’
m 2 ⎡ 1 ⎤ ()Nn []()1+δm0 π ⎢ ⎥ = Cn,m ⎣2n +2⎦
⎡2n+2⎤ ⎡ 1 ⎤ ⎢ ⎥ []()1+δm0 π ⎢ ⎥ = Cn,m ⎣1+δm0 ⎦ ⎣2n +2⎦
Cn,m = π
Orthogonality
2π1 Zm' (ρ,θ)Zm(ρ,θ)ρdρdθ = πδ δ ∫∫ n' n n'n m'm 0 0
16 The First Few Zernike Polynomials
0 Z0 (ρ,θ) =1 −1 Z1 ()ρ,θ = ρsin θ 1 Z1()ρ,θ = ρcosθ −2 2 Z2 ()ρ,θ = 6()ρ sin 2θ 0 2 Z2 ()ρ,θ = 3()2ρ −1 2 2 Z2 ()ρ,θ = 6()ρ cos 2θ
Zernike Polynomials ρ
0 Z0
−1 1 Z1 Z1 Polynomial, Polynomial,
−2 0 2 Z2 Z2 Z2 Radial
−3 −1 1 3 Z3 Z3 Z3 Z3
−4 −2 0 2 4 Z4 Z4 Z4 Z4 Z4 Azimuthal Frequency, θ
17 Caveats to the Definition of Zernike Polynomials • At least six different schemes exist for the Zernike polynomials. • Some schemes only use a single index number instead of n and m. With the single number, there is no unique ordering or definition for the polynomials, so different orderings are used. • Some schemes set the normalization to unity for all polynomials. • Some schemes measure the polar angle in the clockwise direction from the y axis. • The expansion coefficients depend on pupil size, so the maximum radius used must be given. • Some groups fit OPD, other groups fit Wavefront Error. • Make sure which set is being given for a specific application.
Another Coordinate System
y NON- STANDARD Normalized Polar Coordinates: r ρ = φ rmax ρ x 1 −1⎛ x ⎞ φ = tan ⎜ ⎟ ⎝ y ⎠ ρ ranges from [0, 1] φ ranges from [-180°, 180°]
18 Zernike Polynomials - Single Index ANSI STANDARD ρ Starts at 0 Z 0 Left-to-Right Top-to-Bottom Z1 Z2 Polynomial, Polynomial,
Z3 Z4 Z5 Radial
Z6 Z7 Z8 Z9
Z10 Z11 Z12 Z13 Z14 Azimuthal Frequency, θ
Other Single Index Schemes NON-
Z STANDARD 1 Starts at 1 cosines are even terms Z Z 2 3 sines are odd terms
Z4 Z5 Z6
Z7 Z8 Z9 Z10
Z11 Z12 Z13 Z14 Z15 Noll, RJ. Zernike polynomials and atmospheric turbulence. J Opt Soc Am 66; 207-211 (1976).
Also Zemax “Standard Zernike Coefficients”
19 Other Single Index Schemes NON-
Z STANDARD 1 Starts at 1 increases along diagonal Z2 Z3 cosine terms first 35 terms plus two extra
Z4 Z5 Z6 spherical aberration terms No Normalization!!!
Z7 Z8 Z10 Z11
Z9 Z12 Z13 Z17 Z18
Zemax “Zernike Fringe Coefficients”
Also, Air Force or University of Arizona
Other Single Index Schemes NON- • Born & Wolf • Malacara STANDARD • Others??? Plus mixtures of non-normalized, coordinate systems.
Use two indices n, m to unambiguously define polynomials. Use a single standard index if needed to avoid confusion.
20 Examples
Example 1: 4mm 4m
0.25 D of myopia for a 4 mm pupil (rmax = 2 mm)
r 2 ()2ρ 2 ρ2 1 1 W = = = = Z0 ()ρ,θ + Z0 ()ρ,θ 8000 8000 2000 4000 0 4000 3 2
Examples
Example 2: 2mm 1m
1.00 D of myopia for a 2 mm pupil (rmax = 1 mm)
r 2 ρ2 1 1 W = = = Z0 ()ρ,θ + Z0 ()ρ,θ 2000 2000 4000 0 4000 3 2
Same Zernike Expansion as Example 1, but different rmax.
Always need to give pupil size with Zernike coefficients!!
21 RMS Wavefront Error
• RMS Wavefront Error is defined as
(W(ρ,φ))2 ρdρdφ ∫∫ 2 RMSWFE = = ∑()a n,m ∫∫ρdρdφ n>1,all m
Zeroth Order Zernike Polynomials This term is called Piston and is usually ignored. The surface is constant over the entire circle, so no error or variance exists.
0 Z0
22 First Order Zernike Polynomials
These terms represent a tilt in the wavefront.
−1 1 Z1 Z1 −1 1 Combining these terms results in a a1−1Z1 (ρ,θ) + a11Z1(ρ,θ) general equation for a plane, thus = a ρsin θ + a ρcosθ by changing the coefficients, a plane 1−1 11 y x at any orientation can be created. = a + a This rotation of the pattern is true 1−1 r 11 r for the sine/cosine pairs of Zernikes max max
Second Order Zernike Polynomials
−2 0 2 Z2 Z2 Z2
These wavefronts are what you would expect from Jackson crossed cylinder J0 and J45 and a spherical lens. Thus, combining these terms gives any arbitrary spherocylindrical refractive error.
23 Third Order Zernike Polynomials
−3 −1 1 3 Z3 Z3 Z3 Z3
The inner two terms are coma and the outer two terms are trefoil. These terms represent asymmetric aberrations that cannot be corrected with convention spectacles or contact lenses.
Fourth Order Zernike Polynomials
−4 −2 0 2 4 Z4 Z4 Z4 Z4 Z4 4th order Spherical 4th order Quadroil Astigmatism Aberration Astigmatism Quadroil
These terms represent more complex shapes of the wavefront. Spherical aberration can be corrected by aspheric lenses.
24 Discrete data
• Up to this point, the data has been continuous, so we can mathematically integrate functions to get expansion coefficients. • Real-world data is sampled at discrete points. • The Zernike polynomials are not orthogonal for discrete points, but for high sampling densities they are almost orthogonal.
Speed • The long part of calculating Zernike polynomials is calculating factorial functions. ⎪⎧ NmR m (ρ)cosmθ ;for m ≥ 0 Zm (ρ,θ) = n n n ⎨ m m ⎩⎪ − Nn Rn (ρ)sinmθ ;for m < 0
(n− m )/ 2 s m (−1) (n −s)! n−2s Rn (ρ) = ∑ ρ s=0 s![]0.5(n + m) −s ![]0.5(n − m) −s !
25 Speed • Chong et al.* developed a recurrence relationship that avoids the need for calculating the factorials. • The results give a blazing fast algorithm for calculating Zernike expansion coefficents using orthogonality.
*Pattern Recognition, 36;731-742 (2003).
Least Squares Fit
⎛ a ⎞ 0 −1 1 m ⎜ 00 ⎟ ⎛ Z0 (x1, y1) Z1 (x1, y1) Z1(x1, y1) L Zn (x1, y1) ⎞ ⎛ f (x1, y1) ⎞ ⎜ ⎟⎜a1−1 ⎟ ⎜ ⎟ 0 −1 1 m f (x , y ) ⎜ Z0 (x 2 , y2 ) Z1 (x 2 , y2 ) Z1(x 2 , y2 ) L Zn (x 2 , y2 ) ⎟⎜ ⎟ ⎜ 2 2 ⎟ ⎜ ⎟ a11 = ⎜ ⎟ ⎜ ⎟ M ⎜ M M M L M ⎟⎜ ⎟ ⎜ ⎟ ⎜ 0 −1 1 m ⎟ M ⎜ ⎟ ⎝ Z0 (x N , yN ) Z1 (x N , yN ) Z1(x N , yN ) L Zn (x N , yN )⎠⎜ ⎟ ⎝f (x N , yN )⎠ ⎝a nm ⎠
ZA = F ZT ZA = ZTF −1 A = ()ZT Z ZTF
26 Gram-Schmidt Orthogonalization
• Examines set of discrete data and creates a series of functions which are orthogonal over the data set. • Orthogonality is used to calculate expansion coefficients. • These surfaces can then be converted to a standard set of surfaces such as Zernike polynomials. Advantages • Numerically stable, especially for low sampling density. Disadvantages • Can be slow for high-order fits • Orthogonal functions depend upon data set, so a new set needs to be calculated for every fit.
Elevation Fit Comparison 32 Orders or 560 total polynomials
0.125 Seconds 10 Seconds Chong Algorithm Gram-Schmidt
27 Shack-Hartmann Wavefront Sensor Lenslet Array Lenslet Array
Eye Eye Plane Wavefronts Aberrated Wavefronts Perfect wavefronts give a uniform grid of points, whereas aberrated wavefronts distort the grid pattern.
Least Squares Fit
⎡ dV1(x1, y1) / dx dV2 (x1, y1) / dx L dVJ (x1, y1) / dx ⎤ ⎡ dW(x1, y1) / dx ⎤ ⎢ dV (x , y ) / dx dV (x , y ) / dx dV (x , y ) / dx ⎥ ⎢ dW(x , y ) / dx ⎥ ⎢ 1 2 2 2 2 2 L J 2 2 ⎥ ⎢ 2 2 ⎥ ⎢ M M M M ⎥⎡a1 ⎤ ⎢ M ⎥ ⎢ ⎥ ⎢ ⎥ dV (x , y ) / dx dV (x , y ) / dx dV (x , y ) / dx ⎢a ⎥ dW(x , y ) / dx Z = ⎢ 1 N N 2 N N L J N N ⎥⎢ 2 ⎥ = ⎢ N N ⎥ ⎢ ⎥ ⎢ ⎥ dV1(x1, y1) / dy dV2 (x1, y1) / dy L dVJ (x1, y1) / dy ⎢ M ⎥ dW(x1, y1) / dy ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ dV1(x 2 , y2 ) / dy dV2 (x 2 , y2 ) / dy L dVJ (x 2 , y2 ) / dy ⎥⎣a J ⎦ ⎢ dW(x 2 , y2 ) / dy ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ M M M M ⎥ ⎢ M ⎥ ⎣⎢dV1(x N , yN ) / dy dV2 (x N , yN ) / dy L dVJ (x N , yN ) / dy⎦⎥ ⎣⎢dW(x N , yN ) / dy⎦⎥
ZA = F Again, conceptually easy to understand, T T although this can be relatively slow for Z ZA = Z F high order fits. −1 A = ()ZT Z ZTF
28 Example Image
Wavefront Reconstruction
PSF
29