zernike_normalization#

pyzernike.zernike_normalization(n: Integral, m: Integral) → float[source]#
pyzernike.zernike_normalization(n: Sequence[Integral], m: Sequence[Integral]) → List[float]

Compute the normalization factors of Noll [1] of the Zernike polynomials \(Z_{n}^{m}\).

The polynomials computed by pyzernike are not normalized by default (\(Z_{n}^{m}(1, \theta)\) has an amplitude of 1). The normalized polynomials \(N_{n}^{m} Z_{n}^{m}\) are orthonormal on the unit disk for the inner product averaged over the disk:

\[\frac{1}{\pi} \int_{0}^{2\pi} \int_{0}^{1} N_{n}^{m} Z_{n}^{m}(\rho, \theta) \, N_{n'}^{m'} Z_{n'}^{m'}(\rho, \theta) \, \rho \, d\rho \, d\theta = \delta_{nn'} \delta_{mm'}\]

with:

\[\begin{split}N_{n}^{m} = \sqrt{(2 - \delta_{m0})(n + 1)} = \begin{cases} \sqrt{n + 1} & \text{if } m = 0 \\ \sqrt{2(n + 1)} & \text{if } m \neq 0 \end{cases}\end{split}\]

For \(n > 0\), the normalized polynomial has a unit root mean square over the disk, so that its coefficient in a decomposition is directly the RMS of the corresponding aberration. The coefficients \(c_j\) of the not normalized polynomials and \(c'_j\) of the normalized polynomials of the same function are related by \(c'_j = c_j / N_j\) (see pyzernike.zernike_coefficients_convert()).

The first factors are:

n

m

\(N_{n}^{m}\)

0

0

1

1

±1

2

2

0

\(\sqrt{3}\)

2

±2

\(\sqrt{6}\)

3

±1

\(\sqrt{8}\)

3

±3

\(\sqrt{8}\)

4

0

\(\sqrt{5}\)

Shape of the inputs and of the output. n and m can be two integers, or two sequences of integers (lists, tuples or 1D numpy arrays) with the same length:

  • If n and m are integers, a single float is returned.

  • If n and m are sequences, a list of floats is returned.

  • Mixing an integer and a sequence is not allowed.

See also

Parameters:
  • n (Union[Integral, Sequence[Integral], numpy.ndarray]) – The radial order, or the sequence of radial orders, of the Zernike polynomials.

  • m (Union[Integral, Sequence[Integral], numpy.ndarray]) – The azimuthal frequency, or the sequence of azimuthal frequencies, of the Zernike polynomials. Must be of the same kind as n (integer or sequence) and, for sequences, of the same length.

Returns:

If n and m are integers, the normalization factor \(N_{n}^{m}\).

If n and m are sequences, the list of the normalization factors, in the same order as n and m.

Return type:

Union[float, List[float]]

Raises:
  • TypeError – If n or m is not an integer, a sequence of integers or a 1D numpy array of integers, or if an integer is mixed with a sequence.

  • ValueError – If n and m do not have the same length, or if a pair (n, m) is not a valid Zernike order (\(n < 0\), \(|m| > n\) or \((n - m)\) odd).

References

Examples

Normalization factor of the defocus \(Z_{2}^{0}\):

from pyzernike import zernike_normalization

print(zernike_normalization(2, 0))  # Output: 1.7320508075688772

Normalize the polynomials computed without normalization:

import numpy
from pyzernike import zernike_polynomial, zernike_normalization

rho, theta = numpy.meshgrid(numpy.linspace(0, 1, 100), numpy.linspace(0, 2 * numpy.pi, 100))
n, m = [2, 2, 3], [-2, 0, 1]
Z = zernike_polynomial(rho, theta, n, m, to_list=False)
Z_normalized = Z * numpy.reshape(zernike_normalization(n, m), (-1, 1, 1))
# same as zernike_polynomial(rho, theta, n, m, normalize=True, to_list=False)