Skip to content

Staining protocols

pyHisto is not tied to one stain. Colour deconvolution needs two stain vectors (plus a Residual), and the calibration measures both from your slides whatever the stains are. A staining protocol only tells pyHisto what to call the two measured vectors and in which order to return them.

Built-in protocols

Protocol Example (RGB | stain 1 | stain 2) Stains (1 / 2) Typical use Third dye (not estimated) Reference vectors from
psr-fg (default) PSR/FG mouse lung: RGB, PSR, FG
Mouse lung, week 16 · credits
PSR / FG (Fast Green) Collagen with a Fast Green counterstain for non-collagenous protein Picric acid and any nuclear stain go to the Residual pyHisto's original histo calibrate default (rough PSR / Fast Green directions)
psr PSR-only human liver tile: RGB, PSR, picric-acid background
Human liver (MASLD), 512 px tile · credits
PSR / Background (picric acid) Picrosirius Red without a counterstain Any nuclear stain (e.g. Weigert's hematoxylin) goes to the Residual PSR as in psr-fg; picric acid an approximate yellow (pure blue absorber, the "CMY" yellow of Fiji's Colour Deconvolution)
masson-trichrome Masson's trichrome mouse kidney: RGB, collagen, cytoplasm
Mouse kidney · credits
Collagen (aniline/methyl blue) / Cytoplasm (Biebrich scarlet/ponceau-fuchsin) Masson's trichrome: collagen blue, cytoplasm and muscle red Iron hematoxylin (nuclei): not one of the two vectors; in principle it goes to the Residual, but being blue-black it mostly lands in the blue channel (see Home) Fiji Colour Deconvolution, "Masson Trichrome"
he H&E crop: RGB, hematoxylin, eosin
Brightfield H&E (tissue not stated by the source) · credits
Hematoxylin / Eosin H&E — QuPath 0.7.0 defaults
h-dab No open example yet. Hematoxylin / DAB Brightfield IHC — QuPath 0.7.0 defaults (Ruifrok & Johnston)
azan-mallory No open example yet. Collagen (aniline blue) / Nuclei/cytoplasm (azocarmine) Azan (Heidenhain) / Mallory trichrome Orange G goes to the Residual Fiji Colour Deconvolution, "Azan-Mallory"
alcian-blue-h No open example yet. Alcian blue / Hematoxylin Acidic mucins / GAGs A nuclear-fast-red counterstain is not modelled Fiji Colour Deconvolution, "Alcian blue & H"

Examples: One crop per protocol where an open or credited image exists. Each row shows the white-corrected RGB crop and its two stains, each re-drawn alone in its own colour (white = none), from vectors estimated on that crop alone with histo.stain.estimate(rgb, reference=histo.stain.reference(name)) and drawn with histo.stain.qc.channel_separation.

histo calibrate --list-protocols prints this list with the reference vectors, and histo.stain.protocol_info(name) returns the description, third-dye note and exact source of each one. Names are case-insensitive and common aliases work (trichrome, h&e, hdab, picrosirius, ...).

The reference never sets the values

The reference vectors only need to point roughly the right way. The calibrated vectors always come from your slides; two datasets with the same protocol get different vectors, and that is the point.

How naming and ordering work

QuPath's "Estimate stain vectors" finds two directions \(\mathbf{s}_1, \mathbf{s}_2\) in OD space (see Stain vectors and calibration); which one comes first is arbitrary. With the protocol's reference vectors \(\mathbf{r}_1, \mathbf{r}_2\) and \(\theta(\mathbf{u}, \mathbf{v})\) the angle between two vectors, the two are swapped when

\[ \min\big(\theta(\mathbf{s}_1, \mathbf{r}_2),\ \theta(\mathbf{s}_2, \mathbf{r}_1)\big) \;<\; \min\big(\theta(\mathbf{s}_1, \mathbf{r}_1),\ \theta(\mathbf{s}_2, \mathbf{r}_2)\big), \]

and then named after the reference: stain 1 gets the name of \(\mathbf{r}_1\), stain 2 that of \(\mathbf{r}_2\). For H&E (he) QuPath uses a different rule, and so does pyHisto: the vector with the larger red optical density is hematoxylin.

Choosing a protocol

pixi run histo calibrate zarr/*.ome.zarr --protocol masson-trichrome --out qc/trichrome
pixi run histo calibrate --list-protocols
import pyHisto as histo

ref = histo.stain.reference("masson-trichrome")
cal = histo.stain.calibrate(slides, regions, reference=ref)

Pick the protocol by what is on the slide, not by what you want to measure: a PSR section with a Fast Green counterstain is psr-fg, the same stain without counterstain is psr. The chosen protocol is stored in calibration.json (params.protocol) and its stain names become the keys of stain_map.json.

A stain that is not listed

Write a stain-map JSON with your two stains, e.g. measured once in QuPath (Analyze ▸ Preprocessing ▸ Estimate stain vectors) or taken from the literature (the numbers here are only an illustration):

{"Orcein": [0.36, 0.67, 0.65], "Counterstain": [0.80, 0.50, 0.33]}

and pass it with --reference my_stains.json (CLI; this overrides --protocol) or reference=histo.StainMatrix.from_json("my_stains.json") (Python). As with the built-in protocols, the file only names and orders the two vectors; the values are still measured from your slides.