Zernike moments on the unit disc

Image analysis

About this lecture

Legendre moments fixed the conditioning, but they live on a square, and a square does not turn into itself under rotation. Move to a disc:

  • Zernike polynomials: a Fourier series in the angle times a polynomial in the radius, orthogonal on the unit disc.
  • Zernike moments Z_{nm}; reconstruction as in the previous unit.
  • Rotation only turns the phase of Z_{nm}: the magnitudes |Z_{nm}| are rotation invariant, for free.
  • What they lose (6 and 9), how pixels and arithmetic spoil them, and where they come from (optics).

Slides titled The math give the formulas and proofs; the ideas are complete without them.

Why a disc?

  • Rotation is natural in polar coordinates (\rho, \theta): turning the image by \alpha is the shift \theta \to \theta + \alpha.
  • A function of \theta on a circle has a Fourier series \sum_m c_m e^{im\theta}; a shift multiplies each term by a phase e^{im\alpha} and leaves its size alone (the shift theorem of the Fourier unit).
  • A square is not rotation symmetric: rotating the image moves its corners in and out of the square, and Legendre moments of a rotated image are complicated mixtures of the original ones.

So: build a basis on the unit disc whose angular part is e^{im\theta}.

A square and the same square rotated by 30 degrees (dashed): the corners stick out of the original square. A disc and the disc rotated by 30 degrees: the same set.

Zernike polynomials

V_{nm}(\rho, \theta) = R_{nm}(\rho)\, e^{im\theta}, \qquad n \ge 0,\ |m| \le n,\ n - |m| \text{ even}.

  • m: how many times the pattern repeats around the circle (the angular frequency).
  • n: the degree of the radial polynomial; R_{nm} has (n - |m|)/2 zeros inside the disc.
  • Small ones: R_{00} = 1, R_{11} = \rho, R_{20} = 2\rho^2 - 1, R_{22} = \rho^2, R_{31} = 3\rho^3 - 2\rho, R_{33} = \rho^3, R_{40} = 6\rho^4 - 6\rho^2 + 1.
  • Real versions: R_{nm}\cos m\theta and R_{nm}\sin m\theta.

The Zernike polynomials for n = 0 to 4 as a pyramid of images on the unit disc, red positive and blue negative, labelled n, m: the angular frequency m grows outwards in each row, the radial degree n downwards, with more rings for larger n.

The math: Zernike polynomials are orthogonal

\iint_{\rho \le 1} \overline{V_{nm}}\, V_{n'm'}\, \rho\,d\rho\,d\theta = \frac{\pi}{n + 1}\,\delta_{nn'}\delta_{mm'}.

  • Angular part: \int_0^{2\pi} e^{i(m' - m)\theta}\,d\theta = 2\pi\,\delta_{mm'} (the Fourier basis).
  • Radial part, same m: \int_0^1 R_{nm} R_{n'm}\,\rho\,d\rho = \frac{1}{2(n+1)}\delta_{nn'}, orthogonal with the weight \rho (the area element of polar coordinates). Example: \int_0^1 (2\rho^2 - 1)\cdot 1 \cdot \rho\,d\rho = \tfrac12 - \tfrac12 = 0.
  • General formula: R_{nm}(\rho) = \sum_{k=0}^{(n-|m|)/2} \frac{(-1)^k (n-k)!}{k!\,\left(\frac{n+|m|}{2} - k\right)!\,\left(\frac{n-|m|}{2} - k\right)!}\,\rho^{n - 2k}.
  • R_{nm}(1) = 1 for all n, m.

Try it: the Zernike polynomials

Zernike moments

The coefficients of an image in this basis, on the disc:

Z_{nm} = \frac{n + 1}{\pi} \iint_{\rho \le 1} I(\rho, \theta)\, \overline{V_{nm}(\rho, \theta)}\,\rho\,d\rho\,d\theta.

  • Complex numbers; for a real image Z_{n,-m} = \overline{Z_{nm}}, so only m \ge 0 is needed: up to order N there are (N+2)^2/4 of them for even N (9 at N = 4, 121 at N = 20), the same (N+1)(N+2)/2 real numbers as before.
  • Reconstruction exactly as with Legendre: \hat I_N = \sum_{n \le N}\sum_m Z_{nm} V_{nm}, the orthogonal projection onto the polynomials of degree \le N on the disc.
  • The image must be centred on the disc: put the disc’s centre at the centroid and choose its radius from m_{00} or the farthest object pixel. That makes the moments translation and scale invariant.

Zernike moments as pseudocode

for every pixel inside the disc (ρ ≤ 1):            # ρ, θ of the pixel centre, y up
    Z[n][m] = Z[n][m] + I(x, y) · R_nm(ρ) · (cos mθ − i sin mθ) · ΔA
Z[n][m] = (n + 1)/π · Z[n][m]                      # ΔA = area of one pixel
rebuild:  Î(ρ, θ) = sum of Z[n][0]·R_n0(ρ) + 2·Re( Z[n][m]·R_nm(ρ)·e^{imθ} ), m > 0
  • Only m \ge 0 is computed: Z_{n,-m} is the conjugate of Z_{nm}.
  • Pixels outside the disc are ignored, and stay 0 in the rebuilt image.

Rotation: only the phase turns

Rotate the image by \alpha (counter-clockwise). Every pixel moves from angle \theta to \theta + \alpha, and

Z_{nm} \;\to\; Z_{nm}\, e^{-im\alpha}.

  • |Z_{nm}| does not change: a rotation-invariant feature for every (n, m).
  • The phase turns by -m\alpha: m times as fast as the image. Z_{n0} is real and does not turn at all.
  • The same story as the complex moments c_{pq} of the invariants unit: each Z_{nm} is a combination of the c_{pq} with |p - q| = m. Zernike moments are those invariants written in an orthogonal basis, so each one carries new information.

A blob and the blob rotated by 60 degrees inside the dashed unit disc; below, the bars of |Z_nm| for n up to 8 of both, which coincide (largest difference 1.5 per cent). The phase of Z22 turns from −67 to 174 degrees, by −120 degrees = −2 · 60 degrees.

Try it: rotate, and compare |Z_{nm}|

What the magnitudes lose

  • The phase: a shape and its rotated copy have the same |Z_{nm}|. So do 6 and 9, M and W, a b and a q.
  • Mirror images: a reflection conjugates every Z_{nm} (up to a sign (-1)^m for a left–right mirror), so the magnitudes are the same: b and d too.
  • Choose the invariance the task needs, not the most: to tell 6 from 9, keep a phase (e.g. relative to the phase of a reference moment).
  • Low orders are robust and coarse; high orders describe detail and are sensitive to noise. Orthogonality means each moment adds new information (Teh & Chin, 1988, compare the noise sensitivity of the moment families).

A handwritten-style 6 and the same 6 turned by 180 degrees, which is a 9, each in the unit disc; below, their |Z_nm| for n up to 8: the bars are identical.

Discretisation and arithmetic

  • Square pixels on a round domain. The inscribed disc of a 64 \times 64 image holds 3228 of the 4096 pixels (79 %): the corners are ignored. A circumscribed disc covers everything but contains empty regions; either way the boundary is a staircase.
  • Sampling vs integrating, as for Legendre: the sampled V_{nm} are only nearly orthogonal; the error grows with the order.
  • Arithmetic. The factorial formula sums terms of alternating sign that are huge compared with the result (|R_{nm}| \le 1): for R_{40,0} the largest term is 5 \times 10^{13}. Computed that way, R_{40,0} is off by up to 0.015, R_{50,0} by 73. A recurrence in n (Kintner; Prata & Rusch 1989) avoids the cancellation.

Top: a 16 × 16 pixel grid with the pixels whose centres lie in the inscribed disc shaded, a staircase along the circle; at 64 × 64 the disc holds 3228 of the 4096 pixels. Bottom: the error of the factorial formula against rho on a log scale, growing towards the rim: at most 7.7 × 10^−7 for R30,0, 0.015 for R40,0 and 73 for R50,0.

Try it: the disc and the noise

Where Zernike polynomials come from

Frits Zernike introduced them in 1934 to analyse the knife-edge test of mirrors, on the way to phase-contrast microscopy (Nobel prize 1953).

Today they are the standard language for wavefront aberrations of lenses: the deviation of a wavefront over the round pupil is written as \sum a_{nm} V_{nm}.

  • V_{20}: defocus; V_{2,\pm 2}: astigmatism; V_{3,\pm 1}: coma; V_{3,\pm3}: trefoil; V_{40}: spherical aberration.
  • Adaptive optics and objective-lens corrections are specified in these terms (the image-formation day’s pupil function).

Top row: a flat wavefront over the round pupil and wavefronts of 0.6 waves of defocus, astigmatism, coma and spherical aberration. Bottom row: the image of a point for each: a small Airy spot, a wide ring, a cross, a comet-shaped flare, and a spot with rings.

Simulated: pupil wavefront 0.6\,V_{nm} (in waves), image of a point = |\text{Fourier transform of the pupil}|^2.

Summary

  • Zernike polynomials V_{nm} = R_{nm}(\rho) e^{im\theta}: angular Fourier series times radial polynomials, orthogonal on the unit disc (weight \rho).
  • Zernike moments Z_{nm}: projections onto V_{nm}; Z_{n,-m} = \overline{Z_{nm}}; reconstruction by summing, as with Legendre.
  • Rotation multiplies Z_{nm} by e^{-im\alpha}: |Z_{nm}| is rotation invariant (and mirror invariant), but loses the difference between 6 and 9.
  • Centre the disc on the centroid; expect errors from square pixels on the round domain, sampling, and cancellation in the factorial formula (use a recurrence).