Skip to content

Stain variance is a measurement, not a verdict

The idea in plain words

Even on one slide, the colour of a stain (PSR in the examples on this page, from a PSR + Fast Green dataset) is not perfectly constant: section thickness, fibre density, local dye uptake and scanner focus all shift it a little. Calibration therefore does two things:

  1. it returns one set of vectors (the robust median), and
  2. it measures how much the individual regions disagreed with it.

That second number is the stain variance. It is information for you, the analyst, not a grade.

Reading the table

stain variance across regions (deg):
  stain       median    mean      sd     p95     max  n_used
  PSR           6.39    6.39    3.71   12.72   12.84      12
  FG            2.00    2.17    1.13    3.92    4.96      12
  Residual      2.80    3.51    2.28    7.16   10.15      12

For every used region, pyHisto computes the angle (in degrees) between that region's vector \(\mathbf{u}\) and the calibrated vector \(\mathbf{v}\):

\[ \theta = \arccos\!\left(\frac{\mathbf{u}\cdot\mathbf{v}}{\lVert\mathbf{u}\rVert\,\lVert\mathbf{v}\rVert}\right), \qquad 0^\circ \le \theta \le 180^\circ \]

(the cosine is clipped to \([-1, 1]\); the sign is not folded, so opposite vectors are 180° apart). The table summarises these angles per stain:

Column Meaning
median the typical region's deviation
mean, sd average and (population) standard deviation
p95 95th percentile (linear interpolation): all but the most unusual 5 %
max the most unusual region
n_used regions that contributed (single-stain / failed ones excluded)

The per-region angles are in calibration.json (deviations) and in the caption of every region on the QC sheet (PSR 5.3° FG 1.9°).

For orientation: the estimator itself reproduces QuPath within 1°, so deviations of a few degrees are real differences between regions, not numerical noise.

A measurement, not a grade

Stain colour is not a constant of the slide. The same dye looks slightly different in different places, for reasons that are real:

  • Tissue. Picrosirius Red bound to thin alveolar fibres and to dense perivascular bundles absorbs light differently; so does a dye in a thick versus a thin part of the section.
  • Preparation. Section thickness, staining time, washing and mounting vary across a slide and between slides.
  • Imaging. Focus, lamp brightness and the white level of each scan shift the recorded colours a little.

The spread of the per-region vectors puts a number on all of this together. It answers how much does the stain colour vary in this dataset? There is no single angle above which a calibration becomes "wrong": whether 3° or 10° matters depends on the tissue, the stain protocol and the size of the effect you want to measure.

So the useful questions are:

  1. Is the spread small compared with what you are measuring? If the groups you compare differ by a few percentage points of collagen, check how much the result moves when the stain vectors change by the observed spread (for example by recalculating with a few of the per-region vectors).
  2. Where does the spread come from? Look at the regions with the largest deviation on the QC sheet. A region full of blood, folds or out-of-focus tissue explains a large angle; a region of normal tissue that simply stains differently is part of the real variation.
  3. Is it consistent across datasets? Comparing the variance table between staining batches is a quick way to spot a batch that behaves differently.

The QC report therefore shows the numbers and the images side by side and leaves the interpretation to you.

What to do with a large spread

  • Look at the regions with the largest deviation on the QC sheet. Is the PSR square showing collagen? Is FG leaking into it?
  • Check that the regions cover the dataset: several files, different parts of the tissue.
  • Compare slides: in calibration.json, group deviations by the region's slide_id. A whole slide that deviates suggests a staining batch effect, which may justify a separate calibration for that batch.
  • Compare pooled with stains (the "pooled vs calibrated" row in the report): a big difference hints that single-stain areas dominate the tissue.