Cohort processing¶
HistoKit provides a configurable framework for parallel cohort-level processing of WSIs and images saved a single layer (PNG, JPG, TIF).
Instead of executing individual processing methods separately, users can define a multi-stage processing pipeline using a YAML files.
Configuration files¶
HistoKit provides example configurations for processing both single-layer images (e.g., PNG image patches) and multi-resolution whole-slide images (WSIs, e.g., SVS files).
The configuration files are located in the scripts_cohort/configs/
directory.
| Configuration file | Input type | Description |
|---|---|---|
cohort_patches.yaml |
Single-layer images | Processing script for your data |
cohort_wsi.yaml |
Whole-slide images (WSIs) | Processing script for your data |
run_example_patch.yaml |
Single-layer images | Ready to use example |
run_example_wsi.yaml |
Whole-slide images (WSIs) | Ready to use example |
Each configuration file can be customized to specify input data, output directories, segmentation algorithms, and processing parameters.
Processing workflow¶
The cohort processing pipeline consists of independent stages that can be enabled or disabled depending on the analysis requirements.
| Stage | Algorithm | Configuration file | Description |
|---|---|---|---|
| Tissue detection | GaMRed | gamred.yaml |
Tissue region segmentation with GaMRed. |
| Artifact detection | GrandQC | grandqc.yaml |
Artifact segmentation with GrandQC (citation required). |
| Statistics | Stats | stats.yaml |
Computes artifact statistics. |
| GeoJSON | GeoJSON | geojson.yaml |
Exports results in GeoJSON format and saves patch coordinates for TRIDENT. |
Each stage has its own configuration file, allowing processing parameters to be adjusted independently, see algorithms websites for the details.
Previously generated segmentation masks can also be supplied as input to subsequent processing stages, without repeating the entire processing pipeline.
Configuration¶
Cohort processing is controlled through the cohort_wsi.yaml and cohort_patches.yaml
configuration file.
The configuration defines:
- Output storage format.
- Logging settings.
- Enabled processing stages.
- Algorithm selection.
- Paths to stage-specific configuration files.
- Number of parallel workers.
- Overwrite behavior (overwrite existing files or not).
- Locations of previously generated segmentation masks.
Example configuration
For processing images saved as single-layer images (e.g., PNG image patches) provide mag_l0: mag parameter.
With the information about the magnification.
Configuration file¶
| cohort_wsi.yaml | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Example configuration
In the configuration above, only the GeoJSON export stage is enabled. Previously generated artifact segmentation masks are used as input.
Enable additional stages by setting their enabled parameter
to true.
Configuration parameters¶
General settings¶
| Parameter | Type | Example value | Description |
|---|---|---|---|
saver |
str |
hdf5 |
Storage format used for processing results. |
stages |
dict |
— | Defines the individual processing stages and their configuration. |
Logging¶
Logging provides information about cohort processing progress and helps identify slides that could not be processed successfully.
| Parameter | Type | Example value | Description |
|---|---|---|---|
enabled |
bool |
true |
Enables processing logs. |
log_dir |
str |
./outputs/logs |
Logging directory. |
processed_file |
str |
processed.csv |
CSV file with information about successfully processed slides. |
errors_file |
str |
errors.csv |
CSV file with information about processing errors. |
Common stage parameters¶
Each processing stage can be configured independently using the following parameters.
| Parameter | Type | Description |
|---|---|---|
enabled |
bool |
Determines whether the processing stage is executed. |
algorithm |
str |
Identifier of the processing algorithm. |
config_path |
str |
Path to the algorithm-specific YAML configuration file. |
parallel_workers |
int |
Number of parallel workers assigned to the processing stage. |
overwrite |
bool |
Determines whether existing processing results should be overwritten, where supported. |
Parallel processing
The number of parallel workers can be configured separately for each processing stage.
CPU-based operations may benefit from multiple workers, whereas GPU-based artifact segmentation may require fewer workers due to GPU memory limitations.
Adjust these settings according to the available hardware, slide dimensions, and memory requirements.
Processing stages¶
Tissue segmentation¶
The tissue segmentation stage identifies tissue regions and separates them from the slide background.
The GaMRed-based pipeline supports adaptive thresholding, artifact removal, morphological post-processing, and adaptive filtering of small connected components.
tissue_segmentation:
enabled: true
algorithm: gamred
config_path: ./gamred.yaml
parallel_workers: 4
overwrite: false
Detailed algorithm parameters are defined in gamred.yaml (see GaMRed for details).
Artifact segmentation¶
The artifact segmentation stage uses GrandQC-based segmentation to identify histological artifacts within whole-slide images.
artifact_detection:
enabled: true
algorithm: grandqc
config_path: ./grandqc.yaml
parallel_workers: 1
overwrite: false
tissue_source:
dir: /path/to/tissue/masks/
| Parameter | Type | Description |
|---|---|---|
tissue_source.dir |
str or null |
Directory containing previously generated tissue segmentation masks, if provided. |
Detailed model settings and segmentation parameters are defined
in grandqc.yaml.
External model
GrandQC requires pretrained model weights and is subject to separate licensing and citation requirements. See GrandQC for details.
Statistics¶
The statistics stage computes quantitative measurements based on previously generated segmentation results.
statistics:
enabled: true
algorithm: stats
config_path: ./stats.yaml
parallel_workers: 4
artifact_source:
dir: /path/to/artifact/masks/
| Parameter | Type | Description |
|---|---|---|
artifact_source.dir |
str |
Directory containing artifact segmentation masks used for statistical analysis. |
The calculated measurements and output settings are defined
in stats.yaml.
GeoJSON export¶
The GeoJSON stage converts segmentation regions into vector-based annotations that can be used in downstream digital pathology workflows and compatible visualization tools.
geojson:
enabled: true
algorithm: geojson
config_path: ./geojson.yaml
parallel_workers: 3
artifact_source:
dir: /path/to/artifact/masks/
| Parameter | Type | Description |
|---|---|---|
artifact_source.dir |
str |
Directory containing segmentation masks to be converted into GeoJSON annotations. |
Export parameters are defined in geojson.yaml.
Example workflows¶
Full cohort processing¶
Enable all processing stages to perform tissue detection, artifact detection, statistical analysis, and GeoJSON export.
stages:
tissue_detection:
enabled: true
artifact_detection:
enabled: true
statistics:
enabled: true
geojson:
enabled: true
Tissue detection only¶
Use this configuration to generate tissue segmentation masks without performing artifact detection or subsequent analysis.
stages:
tissue_detection:
enabled: true
artifact_detection:
enabled: false
statistics:
enabled: false
geojson:
enabled: false
Analysis of existing segmentation masks¶
If artifact segmentation masks have already been generated, the statistics and GeoJSON stages can be executed independently.
stages:
tissue_detection:
enabled: false
artifact_detection:
enabled: false
statistics:
enabled: true
artifact_source:
dir: /path/to/artifact/masks/
geojson:
enabled: true
artifact_source:
dir: /path/to/artifact/masks/
Outputs¶
The generated outputs depend on the enabled processing stages, the selected storage format, and the configuration of individual algorithms.
| Output | Description |
|---|---|
| Tissue masks | Binary masks identifying tissue regions. |
| Artifact masks | Segmentation masks identifying histological artifacts. |
| Visualizations | Thumbnails, segmentation overlays, and other quality control outputs, depending on the configured collectors. |
| Statistics | Quantitative measurements derived from segmentation results. |
| GeoJSON annotations | Vector representations of segmentation regions. |
| Processing logs | Information about successfully processed slides. |
| Error logs | Information about processing failures. |
Output directory structure¶
An illustrative output directory structure is presented below. The actual directory structure depends on the stage-specific configuration files and enabled processing stages.
outputs/
├── tissue_segmentation/
│ └── gamred/
│ ├── masks/
│ └── visualizations/
│
├── artifact_segmentation/
│ └── grandqc/
│ ├── masks/
│ └── visualizations/
│
├── statistics/
│
├── geojson/
│
└── logs/
├── processed.csv
└── errors.csv
Recommended practices¶
Processing large cohorts
Before processing an entire cohort:
- Test the configuration on a representative subset of slides.
- Inspect tissue and artifact segmentation visualizations.
- Verify the generated outputs.
- Adjust processing magnification and algorithm parameters.
- Select the number of parallel workers according to available computational resources.
- Enable logging to find potential errors during processing.