Quiz: box filters and local statistics
Before this unit: Integral images: any rectangle in four lookups (previous unit); Day 1: Images, filters and frequencies.
See also: Day 3: Bit depth and noise; Day 12: Thresholding; Day 33: Random forests; Day 7: Wavelets.
Short questions to test your understanding. Try each on paper first, then open the answer.
Q1. A 41 \times 41 box filter. How many additions per pixel does it take directly, separably, and with the integral image?
Direct k^2 - 1, separable 2(k-1); the integral image does not depend on k.
Directly 41^2 - 1 = 1680, separably 2 \cdot 40 = 80, with the integral image 6 (3 to build the table, 3 for the four lookups).
Q2. The running sum costs 4 additions per pixel, fewer than the integral image’s 6. Give two situations in which you would still use the integral image.
Any two of: windows of many sizes from one table (a multi-scale feature stack); a window size that changes from pixel to pixel; rectangles that are not centred squares, at arbitrary positions and in any order (as a detector asks for them); several different rectangle sums per pixel (Haar-like features).
Q3. What is the shape of the filter after two passes of the same box? After many passes? Why?
Think of each pass as adding a random shift.
Two passes: a triangle (tent). Many passes: a Gaussian bell. Each pass adds an independent uniform random shift; the sum of many independent shifts is approximately normal (central limit theorem), and the variances add: n(k^2 - 1)/12.
Q4. Two tables, of I and of I^2, give the local mean and variance in any window. How many table lookups per pixel is that?
Four lookups in each table: 8 in total, whatever the window size. Then m = sum / n, s^2 = (sum of squares) / n - m^2.
Q5. Where in a micrograph is the local standard deviation large, and where small?
Large at edges (the window contains both sides) and in textured regions; small in flat regions, where it is just the noise level. That makes it a simple texture feature for every pixel.
Q6. In local contrast normalisation (I - m)/(s + \varepsilon), what does \varepsilon do? What happens in a flat, noisy background with \varepsilon = 0?
\varepsilon keeps the denominator from becoming small. In flat background s is only the noise SD, so with \varepsilon = 0 the noise is scaled up to SD about 1, as strong as real structure. \varepsilon of about the noise level suppresses that, and hardly changes regions with real contrast (s \gg \varepsilon).
Q7. An 8-bit image of 2048 \times 2048 pixels. How many bits does the integral image need? Does it fit in a 32-bit integer? In float32 exactly?
Bit depth + \log_2(number of pixels); float32 is exact for integers up to 2^{24}.
8 + 22 = 30 bits: fits a 32-bit integer. Float32 is exact only up to 2^{24}, so large entries are rounded: not exactly.
Q8. A program stores the integral image in unsigned 32-bit integers, and many entries wrap around. When are the rectangle sums still correct?
Whenever the true sum over the rectangle is below 2^{32}. The wrap-around errors are multiples of 2^{32} and cancel in D - B - C + A modulo 2^{32}.
Q9. Local variances computed as \overline{I^2} - m^2 from float32 tables come out negative in a bright, flat region. Why, and name two fixes.
Both terms are large and nearly equal (about 200^2), and the variance (about 1) is their small difference: the rounding errors of the large numbers are bigger than the answer (cancellation). Fixes: subtract an offset (e.g. the global mean) before building the tables, which does not change the variance; use integer tables; use float64.
Q10. (math) What is the variance of a box of width 7? How many passes of it give variance 16?
(49 - 1)/12 = 4. Variances add, so 4 passes give 16 (\sigma = 4).