Skip to content

Use QuPath as the reference backend

pyHisto's default estimator (method="numpy") is a port of QuPath 0.7.0's "Estimate stain vectors". To compare against real QuPath, pyHisto can run QuPath headless on the same pixels (method="qupath"). This is a reference for checking, not a production path.

Set it up

  1. Install QuPath 0.7.0 (the Linux tarball includes its own Java).
  2. Point pyHisto to the launcher:

    export PYHISTO_QUPATH=/opt/QuPath/bin/QuPath
    

    (or put QuPath on your PATH).

  3. Check:

    pixi run python -c "import pyHisto as histo; print(histo.stain.available_methods())"
    
    ['numpy', 'qupath']
    

The backend runs tools/qupath/estimate_stains.groovy from the pyHisto repository. If pyHisto is installed somewhere without that folder, set PYHISTO_QUPATH_SCRIPT to the script's path.

Use it

pixi run histo calibrate slide.ome.zarr --method qupath --out qc/qupath
sm = histo.stain.estimate(rgb, method="qupath", background=(212, 214, 212))
cal = histo.stain.calibrate(slides, regions, method="qupath", reference=ref)

How it works and its limits

  • The pixels are written to a temporary 8-bit RGB PNG and QuPath runs QuPath script -i pixels.png ... on it; the vectors come back as JSON.
  • Only QuPath's "Auto" defaults are supported (min_stain=0.05, max_stain=1.0, ignore_percentage=1.0); other values raise an error.
  • A fixed background must be whole numbers; without one QuPath uses the mode.
  • QuPath downsamples images larger than 4000 × 4000 pixels.
  • One JVM start per call: slow for many regions.

The live-QuPath tests

Tests that need QuPath carry the requires_qupath marker and are skipped when QuPath is not found. The golden-file tests (stored QuPath results in tests/fixtures/stain/) always run. To run the live comparison too:

PYHISTO_QUPATH=/opt/QuPath/bin/QuPath pixi run test