Colocalisation of two channels

Image analysis

About this lecture

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.

Builds on: Day 46: Colour.

“White means colocalised”?

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.

Three 2D histograms of channel B against channel A, inside the cells, for the three panels of the merge figure. Left, B has A's structures: the cloud is a thin diagonal line, r = 0.99. Middle, independent structures: an L shape along the two axes, r = -0.08. Right, independent structures plus 40 % leakage of A into B: the L plus a second arm rising at slope 0.4, r = 0.32.
  • 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.

Two 2D histograms of the same two-channel image with independent structures and a diffuse signal in both cells. Whole image: a background blob near (10, 10) and the cell pixels near (40, 40) line up diagonally, r = 0.51. Inside the cells only: an L shape around (40, 40), r = -0.08.

The math: correlation and overlap

Over the n pixels of the region, with means \bar A, \bar B:

r = \frac{\sum (A_i - \bar A)(B_i - \bar B)}{\sqrt{\sum (A_i - \bar A)^2 \sum (B_i - \bar B)^2}}, \qquad \text{overlap} = \frac{\sum A_i B_i}{\sqrt{\sum A_i^2 \sum B_i^2}}.

  • 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.

Left: 36 pixel pairs of two 6 by 6 grids; 35 lie in a small cloud between 0 and 3, one pixel sits at (20, 20); Pearson r = 0.85. Right: the same pairs as ranks; the outlier is the top rank in both channels but the other 35 show no rising trend; 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 thresholds t_A and t_B that decide “above background”: the orange specks are noise pixels of A above t_A.

Demo preset A inside B. Left: the green/magenta merge, small green spots inside large magenta blobs. Right: the cell pixels classified by the Costes thresholds tA = 15 and tB = 59: blue where A and B are both above (the spots inside the blobs), grey where only B is above (the rest of the blobs), orange where A is above and B below (scattered noise pixels).

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.

The math: M1 and M2

M_1 = \frac{\sum_i A_i\,[A_i > t_A]\,[B_i > t_B]}{\sum_i A_i\,[A_i > t_A]}, \qquad M_2 = \frac{\sum_i B_i\,[B_i > t_B]\,[A_i > t_A]}{\sum_i B_i\,[B_i > t_B]}.

  • 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:

  1. Fit a line through the scatter plot (orthogonal regression: errors in both channels).
  2. Start with thresholds at the top end of the line: t_A = max of A, t_B on the line.
  3. 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).
  4. Stop when that r reaches 0: the remaining low pixels are uncorrelated noise; everything above is signal.

Demo preset perfect colocalisation. Left: the 2D histogram with the orthogonal regression line and orange dots stepping down it; the stop is near (13.9, 13.8), just above the background blob. Right: r of the pixels below the thresholds against tA, plotted from high to low tA: it stays near 0.99, falls steeply below tA = 50 and reaches 0 at tA = 13.9.

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) −0.5 … 0.5 skewed channels
shift-curve width how fast r falls when B is shifted (unit 2) px structure size, PSF
object fraction within d share of A objects with a B object nearer than d, next to its chance level (unit 3) 0 … 1 detection, density of B
nearest-neighbour distance A → B distance per object (unit 3) nm localisation precision, chromatic shift

Summary

  • 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).