Quiz: finding a shift by sliding and scoring
Before this unit: Day 1: Images, filters and frequencies.
Short questions to test your understanding. Try each on paper first, then open the answer. The shift t of image B is where B must be placed on image A so that they agree; a score compares the pixels of A and B that lie on top of each other.
Q1. Name three situations in microscopy where two images differ by a shift. What is the unknown in each case?
Think of large samples, long experiments and several detectors.
Overlapping tiles of a mosaic (the stage position is not exact), drift between frames of a time-lapse (the sample or the stage creeps), and colour channels recorded with different filters or cameras. In each case the unknown is one vector t = (t_x, t_y): how far B must be moved to lie on A.
Q2. Image B is image A with every grey level doubled. At the true shift, what are SSD and NCC? Which of the two still finds the shift reliably?
SSD compares grey levels; NCC compares patterns.
SSD at the true shift is \sum (f - 2f)^2 = \sum f^2, not 0, and another shift where B’s bright pixels lie on A’s bright pixels can score lower. NCC is exactly 1 at the true shift: it removes the means and divides by the spreads, so a gain (and an offset) does not matter. NCC finds the shift.
Q3. Image A contains a very bright blob that B does not contain. Why can plain cross-correlation (sum of products) put its peak on the blob?
What happens to a sum of products when one factor is large everywhere in a region?
CC adds up A \cdot B over the overlap. Wherever B lands on the bright blob, the products are large simply because A is large there, whether or not the patterns match. CC measures “bright on bright” as much as “same pattern”. NCC removes the mean of the overlap and divides by its spread, so a bright but featureless region scores no better than any other.
Q4. (math) Show that \mathrm{SSD}(t) = \sum f^2 + \sum g^2 - 2\,\mathrm{CC}(t) over the overlap. When does minimising SSD give the same shift as maximising CC?
Expand the square. Which terms depend on t?
(f - g)^2 = f^2 + g^2 - 2fg, summed over the overlap. The two energies \sum f(x+t)^2 and \sum g(x)^2 are over the overlap, so in general they change with t. Only when they are (nearly) the same for every candidate shift, e.g. for circular shifts where the overlap is always the whole image, or for a small template inside a region of even brightness, do SSD and CC pick the same shift.
Q5. Why is NCC unreliable when the overlap is only a few pixels?
What is the correlation coefficient of two random pairs of numbers?
NCC is a correlation coefficient estimated from the pixels of the overlap. With 2 pixels it is always \pm 1; with a handful it is often close to \pm 1 by chance. A search over all shifts then finds a “perfect” match at the edge. Require a minimum overlap (a fraction of the image), or restrict the shifts to those the stage allows.
Q6. A periodic pattern (a grating, a crystal, a regular grid of wells) is registered. What does the NCC curve look like, and what is the consequence?
Shift the pattern by one period.
It has a peak every period, all of nearly the same height: shifting by one period gives the same picture. The score cannot tell which peak is the true shift. Only something that breaks the periodicity (a defect, the border of the pattern, a prior from the stage position) can decide.
Q7. Two 1024 \times 1024 tiles are compared at every possible shift. Roughly how many multiply-adds is that? And within a window of \pm 32 pixels?
All shifts of two N-pixel images cost about N^2; a window of S shifts about N \cdot S.
N = 1024^2 \approx 10^6 pixels, so all shifts cost about N^2 = 1024^4 \approx 1.1 \cdot 10^{12} multiply-adds: about 18 minutes at 10^9 per second. The window has 65^2 = 4225 shifts of about 10^6 pixels each: 4.3 \cdot 10^9, about 4 seconds.
Q8. What is the difference between template matching and registering two tiles?
Look at the sizes of the two images and at what you do with the score map.
The score is the same (usually NCC). In registration both images are large and overlap partly; you want one shift, the best peak. In template matching the template is small and lies completely inside the image at every position; you want all peaks above a threshold, one per copy of the template.