Sie sind auf Seite 1von 7

The Zernike Polynomials

Joshua Cook
10 December 2014
A program in Python to generate, evaluate, and visualize Zernike
polynomials, a family of orthogonal polynomials over the unit disk,
D = {(, )|0 1, 0 2 } and discussions and proofs
of some of their properties. Zernike polynomials are used to describe
aberrations in a lens (e.g., the cornea).

Description
Even and odd Zernike Polynomials are defined respectively as

Znm (, ) = Rnm () cos(m )

and

Znm (, ) = Rnm () sin(m )

(1)

where n, m Z, n m 0, is the azimuthal angle, the radial


distance, and Rm
n ( ), the radial polynomials given by
Rm
n () =

nm
2

k =0

k!

(1)k (n k)!

 n 2 k
k ! n2 m k !

n+m
2

(2)

Rewriting the ratios of factorials in the radial part as products of


Binomial coefficient shows that the coefficients are integer numbers:

Rm
n ()

nm
2

(1)k

k =0

nk
k




n 2k
n2k
nm

k
2

(3)

They satisfy | Znm (, )| 1| for all (0, 1) and all .

Properties of the Zernike Polynomials


Generating the Polynomials
Toward a Recursive Method, we can find a recursive formula
to compute Zernike radial polynomials1 . The following recurrence
relationship has been previously proposed2
Rm
n () =

i
1 h
m
( K2 2 + K3 ) R m
(

)
+
K
R
(

)
4 n4
n2
K1

for
n = m + 4, m + 6, . . .

Barmak Honarvar Shakibaei and


Raveendran Paramesran. Recursive
formula to compute zernike radial
polynomials. Optics letters, 38(14):
24872489, 2013
2
Eric C Kintner. On the mathematical
properties of the zernike polynomials.
Journal of Modern Optics, 23(8):679680,
1976
1

(4)

the zernike polynomials

where the coefficients are given by3

Augustus JEM Janssen and Peter Dirksen. Computing zernike polynomials


of arbitrary degree using the discrete
fourier transform. Journal of the European
Optical Society-Rapid publications, 2, 2007
3

(n + m)(n m)(n 2)
2
K2 = 2n(n 1)(n 2)
K1 =

K3 = m2 (n 1) n(n 1)(n 2)
K4 =

n(n + m 2)(n m 2)
2

To initialize the method we specify cases in which n = m and


n m = 2:4
m
Rm
m () =

(5)

m +2
Rm
( m + 1)r m
m +2 ( ) = ( m + 2 )

(6)

Taking a three-term recurrence relation previously derived5


| m 1|

m
Rm
n ( ) = L1 Rn1 ( ) + L2 Rn2 ( )

Chee-Way Chong, P Raveendran, and


R Mukundan. A comparative analysis
of algorithms for fast computation of
zernike moments. Pattern Recognition,
36(3):731742, 2003
4

Aluizio Prata Jr and WVT Rusch.


Algorithm for computation of zernike
polynomials expansion coefficients.
Applied Optics, 28(4):749754, 1989
5

(7)

where the coefficients L1 and L2 are


2n
m+n
mn
L2 =
m+n

L1 =

We then start with R00 = 1 and can generate all the polynomials.

a Recurrence Relation
Janssen and Dirksen have shown the following integral representation of radial polynomials6
Rm
n () =

1
2

Z 2
k =0

Un cos cos

(8)

where Un is the Chebyshev polynomial of the second kind and of


degree n that satisfies the following7 recurrence relation for n 2
Un ( x ) = 2xUn1 ( x ) Un2 ( x )

(9)

with U0 ( x ) = 1 and U1 ( x ) = 2x.


Clearly, the degree of the radial polynomials is equal to the degree
of the Chebshev polynomials of the second kind.

Augustus JEM Janssen and Peter Dirksen. Computing zernike polynomials


of arbitrary degree using the discrete
fourier transform. Journal of the European
Optical Society-Rapid publications, 2, 2007
6

Barmak Honarvar Shakibaei and


Raveendran Paramesran. Recursive
formula to compute zernike radial
polynomials. Optics letters, 38(14):
24872489, 2013
7

the zernike polynomials

Furthermore, the azimuthal order equals the frequency of the


cosine function.
Therefore, simply set x = cos and multiply by cos(m ) to get

Un ( cos ) cos(m ) = 2 cos Un1 ( cos ) cos(m ) Un2 ( cos ) cos(m )


h
i
Un ( cos ) cos(m ) = cos(|m 1| ) + cos((m + 1) ) Un1 ( cos )cos(m ) Un2 ( cos ) cos(m )
Z 2
0

Un ( cos ) cos(m ) d =

Z 2  h
i
cos(|m 1| ) + cos((m + 1) ) Un1 ( cos )cos(m ) Un2 ( cos ) cos(m ) d
0

Using the integral representation of radial polynomials, we have


the following recurrence relation
h
i
| m 1|
m +1
m
Rm
n ( ) = R n 1 ( ) + R n 1 ( ) R n 2 ( )

(10)

i
h
| m 1|
m
m +1
Rm
n ( ) + R n 2 ( ) = R n 1 ( ) + R n 1 ( )

(11)

or

Orthogonality
Two functions F1 and F2 are orthogonal over a unit cirle if:
Z 1 Z 2
0

F1 F2 dd = 0

For axisymmetric functions with no variance, this reduces to


2

Z 1
0

F1 F2 d = 0

Consider F1 = 2 and F2 = 4 .
2
Consider F3 =

22

2 4 d =

6= 0
4

1 and F4 = 64 62 + 1.

Z 1
0

Z 1

(22 2)(64 62 + 1)d = 0

These are Zernike polynomials. In fact, the Zernike polynomials


are created by subtracting lower order polynomials to create this
orthogonality relationship.

the zernike polynomials

We seek:
Z 1 Z 2
0

(
Ri ()i ( ) R j () j ( )dd = j =

Z 1
0

Ri R j d

Z 2
0

Cj
0

i=j
i 6= j

i j d = j

For a 2-periodic function, we can chose an orthogonal basis (in


fact, orthonormal) in the trigonometric functions sin n and cos n.
Therefore, our problem is reduced to finding an orthogonal radial
basis.
Z 1
0

Ri R j d = j

the zernike polynomials

The Program
The program consists of two files, a View file (menu.py) and a
Controller file (notebook.py).

Controller File
notebook.py consists of two classes Zernike_Polynomial and
Polynomial_Notebook. The first is an object representing a specific

polynomial, where as the second is an object containing multiple


polynomial instances.
Instantiaton of a Notebook Each Polynomial_Notebook has several
notebook level variables and lists. These include:
self.polynomials A list containing polynomials created.
self.density The density to be used for the plotting of polynomials.
self.rho A numpy array containing possible radial values.
self.theta A numpy array containing possible angular values.
self.Rho A meshgrid object associated with radial values.
self.Theta A meshgrid object associated with angular values.

Instantiation of a Polynomial Calling new_polynomial(m,n) initializes a new instance of a Zernike polynomial with the passed m
and n values. It does so by calling the following methods from the
Zernike_Polynomial class.
zernike_Rcoeffs() Uses the binomial relationship defined in eq. 3

to generate the coefficients of the indicial degree.

Figure 1: The polynomial initialization


method.

zernike_even() Generates a mesh-grid, Z_even, representing the

multi-variate function Znm (, ) on the domain [0, 1] [0, 2 ] using


the coefficients generated by zernike_Rcoeffs().
zernike_odd() Generates a mesh-grid, Z_odd, representing the

multi-variate function Znm (, ) on the domain [0, 1] [0, 2 ]


using the coefficients generated by zernike_Rcoeffs().
Preparation of Plots Plots are generated using the matplotlib commands pcolormesh and plot_surface. The meshgrid objects notebook.Rho,
notebook.Theta, poly.Z_even, and poly.Z_odd are used. pcolormesh
uses a polar projection. plot_surface uses a cartesian projection in
three dimensions requiring the conversion of the meshgrid of cartesian coordinates.

Figure 2: Method creating a new


polynomial instance.

the zernike polynomials

View File
menu.py imports both classes from notebook.py and adds another
Menu. Instantiating the Menu also instantiates a new Polynomial_Notebook.

The methods included as part of the Menu are designed to manipulate this notebook. Running the menu from the command line
provides the user with the following menu:
Figure 3: Even and Odd Plots, n = 1,
m=1

Notebook Menu
1. Configure Notebook
2. Add Polynomial
3. Plot Polynomial
4. Compare 2-D and 3-D plots
5. Quit

Configure Notebook Allows the user the change the set density of plots
generated.

Figure 4: Even and Odd Plots, n = 3,


m=3

Add Polynomial Allows the user to add a polynomial to the notebook.


Plot Polynomial Generates and displays a plot of the even and odd
variants of a particular polynomial.
Compare 2-D and 3-D plots Generates and displays a plot of an even
or odd polynomial in two- and three-dimensions of a particular
polynomial.
Quit Quits the program.

Figure 5: 2-D and 3-D plots, Odd


polynomial, n = 3, n = 1

A sample notebook After several polynomials have been added, we


may see the following polynomials in the notebook after running the
Show all Polynomials command:
1: created: 2014-12-06 n,m: 0,0 coeffs: [ 1.]
2: created: 2014-12-06 n,m: 1,1 coeffs: [ 0.

1.]

3: created: 2014-12-06 n,m: 2,0 coeffs: [-1.

0.

2.]

4: created: 2014-12-06 n,m: 2,2 coeffs: [ 0.

0.

1.]

5: created: 2014-12-06 n,m: 3,1 coeffs: [ 0. -2.

0.

3.]

6: created: 2014-12-06 n,m: 3,3 coeffs: [ 0.

0.

0.

1.]

7: created: 2014-12-06 n,m: 4,0 coeffs: [ 1.

0. -6.

0.

6.]

8: created: 2014-12-06 n,m: 4,2 coeffs: [ 0.

0. -3.

0.

4.]

9: created: 2014-12-06 n,m: 4,4 coeffs: [ 0.

0.

0.

1.]

0.

Figure 6: 2-D and 3-D plots, Even


polynomial, n = 4, n = 2

the zernike polynomials

The first 15 Zernike Polynomials

Das könnte Ihnen auch gefallen