Two proteins are labelled with two dyes and imaged in two channels. Are they in the same place? The merged picture invites a yes; this unit turns the question into numbers, and shows how those numbers fool us.
The scatter plot (2D histogram) of the two channels.
Pearson’s r, the overlap coefficient, Manders’ M1 and M2.
Spearman: the rank version, and what one bright pixel does to r.
Thresholds are the method: Costes’ automatic threshold.
The rest of the day asks whether a coefficient is more than chance (unit 2), measures objects and distances instead of pixels (unit 3), and collects what the microscope does to all of it (unit 4).
Slides titled The math give the formulas and proofs; the ideas are complete without them.
Channel A green, channel B magenta: where both are bright the merge is white (yellow in a red/green merge).
Left: B has exactly A’s structures. Middle: B’s structures are independent of A’s. Right: the same independent structures, but 40 % of A leaks into the B channel.
The right image has white spots, and its Pearson r is 0.32 instead of −0.08. Nothing moved: the optics did it.
The eye judges colour, which depends on the display range of each channel (recall: each channel is a grey image with its own display range, colour display). We need numbers, and controls.
The scatter plot
For every pixel in the region of interest, plot (A, B): the 2D histogram of the two channels.
Colocalised structures: the cloud lies along a line through the origin (after the background), B \approx a\,A.
Independent structures: an L shape: bright A with dark B along one axis, bright B with dark A along the other.
Background pixels: a dense blob near (b_A, b_B), the two offsets.
The texture unit drew the same picture with an image and its own shifted copy (the co-occurrence matrix). Every coefficient below summarises this cloud.
Pearson’s correlation
r = the correlation of the two channels over the pixels of the region: +1 a perfect increasing line, 0 no linear relation, −1 a decreasing one.
Unchanged by an offset or a gain of either channel: it centres and scales.
The region matters. Cells bright in both channels on a dark background: the background pixels lie at (dark, dark), the cells at (bright, bright), so r is high even if the structures inside are independent. Demo: 0.51 over the whole image, −0.08 inside the cells.
Lowered by noise (perfectly colocalised but noisy channels: 0.99 at σ = 4, 0.88 at σ = 15).
Raised by bleed-through (0.32 from 40 % leakage).
One number for the whole region: it cannot say which structures overlap.
The math: correlation and overlap
Over the n pixels of the region, with means \bar A, \bar B:
r is the cosine of the angle between the centred vectors A - \bar A and B - \bar B; the overlap coefficient (Manders et al., 1993) is the cosine between the uncentred vectors.
A \mapsto gA + c: r unchanged for g > 0. The overlap coefficient changes with c: a common offset pushes it towards 1 (demo: 0.84 → 0.94 when the offset goes from 10 to 50).
Manders’ k1, k2 split the overlap into two asymmetric parts: k_1 = \sum A_iB_i / \sum A_i^2, k_2 = \sum A_iB_i / \sum B_i^2, and \text{overlap}^2 = k_1 k_2. They change with a gain of one channel; only their product does not.
Noise: for B = aA + c + \varepsilon with independent noise of variance \sigma^2, r = 1/\sqrt{1 + \sigma^2/(a^2 \operatorname{var} A)}: perfect colocalisation reads less than 1.
Rank and robustness
r is a sum of products: one bright pixel pair far from the cloud can carry it.
Spearman’s coefficient is Pearson’s r of the ranks (1 for the darkest pixel, n for the brightest; ties share the average rank).
A pixel at 90 instead of 9 has the same rank: Spearman ignores how bright the outlier is, and it does not care whether B rises with A along a line or along a curve.
It does not fix the region or the background: every pixel counts equally, and in a cell most pixels are background whose ranks are random noise. Demo, perfect colocalisation: Pearson 0.99, Spearman 0.81.
Grid demo, preset “one bright outlier” (right): Pearson 0.85 from a single pixel, Spearman −0.40.
Manders’ M1 and M2
Two questions instead of one: how much of A sits where B is, and how much of B sits where A is.
M1 = of A’s intensity in its above-threshold pixels, the share that lies in pixels where B is also above its threshold.
M2 = the same with A and B swapped.
Asymmetric by design. Small A spots inside large B structures: almost all of A is in B (M1 high), most of B has no A (M2 low). Demo: M1 = 0.79, M2 = 0.32, while r = 0.37 says little.
Weighted by intensity: bright pixels count more than dim ones.
M1 and M2 are only as good as the thresholdst_A and t_B that decide “above background”: the orange specks are noise pixels of A above t_A.
Pearson and Manders as pseudocode
for every pixel i in the region: # means computed first
s_AB += (A_i − mean_A)(B_i − mean_B) # also s_AA, s_BB
if A_i > tA:
sum_A += A_i
if B_i > tB: both_A += A_i
r = s_AB / sqrt(s_AA · s_BB)
M1 = both_A / sum_A # M2: swap A and B
One pass over the region for each coefficient: the region (the mask) is part of the method.
Pearson needs the means first; M1 and M2 need the thresholds first.
Without thresholds (t_A = t_B = 0) and any offset or noise, every pixel is “above”, so M_1 = M_2 = 1 whatever the images (demo, independent channels: 0.999 and 0.997).
Some programs define M_1 = \sum_i A_i [B_i > t_B] / \sum_i A_i, without the threshold on A in the denominator; on images with a background offset the two differ. State which one you use.
Both are fractions in [0, 1]; the chance level for independent channels is not 0 but about the share of B’s region in the image (demo, 75th-percentile thresholds: about 0.2).
Try it: coefficients by hand
Thresholds: Costes’ method
Where is the background? Costes et al. (2004) let the data decide:
Fit a line through the scatter plot (orthogonal regression: errors in both channels).
Start with thresholds at the top end of the line: t_A = max of A, t_B on the line.
Lower t_A step by step (t_B follows the line). After each step compute r of the pixels below the thresholds (A or B below).
Stop when that r reaches 0: the remaining low pixels are uncorrelated noise; everything above is signal.
Then report M1, M2 and r above both thresholds. It is a threshold chosen on a 2D histogram, as Otsu’s threshold is on a 1D histogram (the thresholding day).
Costes’ method needs a positive correlation: with r \le 0 there is no rising line to walk down, and the demo falls back to the 75th percentile of each channel.
The math: the regression line
Orthogonal (total least squares) regression minimises perpendicular distances: its direction is the first principal component of the centred (A, B) cloud (the PCA unit). With s_{AA}, s_{BB}, s_{AB} the sums of squares and products,
\text{slope} = \frac{s_{BB} - s_{AA} + \sqrt{(s_{BB} - s_{AA})^2 + 4 s_{AB}^2}}{2\,s_{AB}}, \qquad \text{intercept} = \bar B - \text{slope}\cdot\bar A.
Ordinary least squares of B on A assumes A has no noise and gives a flatter line; with noise in both channels the orthogonal line is the right one.
The search: t_A^{(k)} = \max A - k\,\Delta, t_B^{(k)} = \text{slope}\cdot t_A^{(k)} + \text{intercept}, stop at the first k with r(\{i : A_i \le t_A \text{ or } B_i \le t_B\}) \le 0.
Try it: colocalisation
What comes next
A coefficient alone is not yet a result:
Is it more than chance? Independent channels do not give exactly 0, and neighbouring pixels are not independent samples: shift curves and block randomisation (unit 2, coloc-null).
Which structures, how far apart? Objects and distances instead of pixels (unit 3, coloc-objects).
What did the microscope add? Background, bleed-through, chromatic shift and the resolution limit, and the order of corrections (unit 4, coloc-confounds).
Catalogue: colocalisation columns
column
measures
range
sensitive to
Pearson r
linear relation of A and B
−1 … 1
region, noise, bleed-through, shift
overlap coefficient
uncentred cosine
0 … 1
offsets
M1, M2
share of A’s (B’s) intensity where the other is present
0 … 1
thresholds
t_A, t_B (Costes)
thresholds from the regression line
intensity
correlation must be > 0
r above thresholds
relation within the signal
−1 … 1
slope of B on A
stoichiometry, if calibrated
bleed-through
Spearman \rho
monotone relation (ranks)
−1 … 1
region, background
randomisation p
how often shuffled B gives r \ge observed (unit 2)
0 … 1
block size
ICQ
share of pixels with (A - \bar A)(B - \bar B) > 0, − 0.5 (unit 2)
The scatter plot of the two channels is the picture; every coefficient summarises it.
Pearson r measures linearity, depends strongly on the region, and ignores offset and gain. The overlap coefficient does not ignore offsets. Spearman uses ranks: robust to one bright pixel, not to the background.
M1, M2 measure how much of each channel lies where the other is, asymmetrically, and are meaningless without thresholds; Costes chooses them from the data.
A number is not yet a result: compare with chance (unit 2), look at objects (unit 3), and correct what the microscope added (unit 4).