Skip to content

GrandQC-based Artifact Segmentation

License Citation Use

HistoKit integrates the artifact segmentation component of GrandQC, developed by Weng et al. (2024). It provides pixel-wise detection of common artifacts in H&E-stained whole-slide images (WSIs) using an EfficientNet-B0 encoder and a UNet++ decoder.

Third-party license and required citation

GrandQC is distributed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Its use is restricted to the permitted academic and non-commercial purposes. The HistoKit license does not override these restrictions.

If you use GrandQC or its benchmark in your research, cite:

Weng, Z. et al. GrandQC: A comprehensive solution to quality control problem in digital pathology. Nature Communications 15, 10685 (2024). https://doi.org/10.1038/s41467-024-54769-y.

See the official citation instructions and original license before use or redistribution.

Tutorial

Open Example

Overview

The original GrandQC framework consists of two modules: tissue-background segmentation and multi-class artifact segmentation. In HistoKit, tissue segmentation can instead be performed using GaMRed-based segmentation, including removal of low-chroma components and marker traces. GrandQC is then applied to the selected regions. If no tissue mask is supplied, the entire slide is processed.

In the original implementation, no overlap between patches was used. HistoKit makes it possible to use overlapping patches and reduce artifacts at patch boundaries. We presented the results in our benchmark paper, where we compared available artifact segmentation methods. This modification resulted in better segmentation performance compared with the original version of GrandQC. See our preprint for details.

Merta, J., Mendelsohn, D., Schoser, B., Polanska, J., & Marczyk, M. (2026). Benchmarking and Improvement of Artifact Segmentation Methods in H&E-Stained Whole Slide Imaging. arXiv preprint arXiv:2610.24037.

Read the preprint | Download PDF

BibTeX citation
@misc{Merta2026ArtifactSegmentation,
  author        = {Merta, Julia and Mendelsohn, Daniel and Schoser, Benedikt and Polanska, Joanna and Marczyk, Michal},
  title         = {Benchmarking and Improvement of Artifact Segmentation Methods in {H\&E}-Stained Whole Slide Imaging},
  year          = {2026},
  eprint        = {2610.24037},
  archivePrefix = {arXiv},
  primaryClass  = {eess.IV},
  doi           = {10.48550/arXiv.2610.24037},
  url           = {https://arxiv.org/abs/2610.24037}
}

Model checkpoints

Download the pretrained artifact models from the official Zenodo record (DOI: 10.5281/zenodo.14041538).

Checkpoint Resolution (µm/px) Approximate magnification
GrandQC_MPP2.pth 2.0 5×
GrandQC_MPP15.pth 1.5 ~7×
GrandQC_MPP1.pth 1.0 10×

Higher-resolution inference generally requires more computation.

models/
└── GrandQC_MPP1.pth

Set model_path to the downloaded file.

Configuration

config/grandqc.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
# Output
saver: hdf5
out_dir: ./outputs/
save_mag: 10.0

# Model
model_path: ./models/GrandQC_MPP1.pth
grandqc_mpp: 1.0

# Inference
device: cuda:0
batch_size: 8
num_workers: 2

# Magnification
segmentation_mag: 10.0
vis_mag: 2.5

# Patches
patch_size_model: 512
patch_size: 512
overlap: 0.75
grid_offset: 0.5
pad_value: 255

# Blending
blending_mode: constant
blending_sigma: 0

# Network preprocessing
encoder: timm-efficientnet-b0
encoder_weights: imagenet
classes: 8

# Outputs
save_confidence_maps: true
save_raw_mask: true

# Visualizations
collectors:
  - name: ArtifactOverlayCollector

Model and inference parameters

Parameter Type Default Description
model_path str / Path / None None Path to the pretrained model.
device str cuda:0 PyTorch inference device.
batch_size int 16 Number of patches in batch.
num_workers int 4 DataLoader worker count.
encoder str timm-efficientnet-b0 Encoder identifier (constant)
encoder_weights str imagenet Encoder weights (constant)
classes int 8 Number of model output channels (constant).

Magnification and patch parameters

Parameter Type Default Description
grandqc_mpp float 1.0 Model resolution metadata (µm/px).
segmentation_mag float 10.0 Magnification at which regions are read and segmented.
vis_mag float 1.0 Magnification of whole-slide visualizations.
patch_size_model int 512 Model patch size (constant)
patch_size int 512 Patch size (constant).
overlap float 0.75 Patch overlap.
grid_offset float 0.5 Offset parameter forwarded to the grid extractor.
pad_value int 255 Padding intensity (constant).
blending_mode str gaussian Patch aggregation mode: constant or gaussian.
blending_sigma float / None None Gaussian parameter passed as sigma_factor to calculate blending weights.

Output parameters

Parameter Type Default Description
saver str Inherited Output saving backend.
out_dir str / Path Inherited Output directory.
save_mag float Inherited Magnification of stored masks.
save_raw_mask bool True Retain per-class aggregated score maps.
save_confidence_maps bool True Save confidence maps or not.
collectors list ArtifactOverlayCollector Visualization collectors.
colors dict See class table Mapping of class names to IDs and RGB colors.

Inference in HistoKit

  1. Read each tissue region at the segmentation magnification, or process the whole slide if no tissue mask is provided.
  2. Extract overlapping patches, pad where necessary, and apply encoder-specific preprocessing.
  3. Run the pretrained model in batches.
  4. Crop predictions and blending weights to valid image coordinates, including the bottom and right boundaries.
  5. Aggregate overlapping predictions and normalize by accumulated weights.
  6. Update channel zero using the background indicator and select the class with the highest aggregated score.
  7. Scale masks to the output magnification, save results, and optionally generate visualizations.

Patch overlap and blending

With a patch size of 512 pixels and overlap of 0.75, the nominal stride is 128 pixels. Overlapping inference reduces reliance on predictions at individual patch boundaries, at the cost of increased computation.

For pixel \(x\) and class \(c\), the aggregated score is:

\[ S_c(x)=\frac{\sum_{i\in I(x)}w_i(x)s_{i,c}(x)}{\sum_{i\in I(x)}w_i(x)} \]

where \(I(x)\) denotes patches covering the pixel, \(s_{i,c}(x)\) is the model score, and \(w_i(x)\) is the blending weight. Uncovered pixels receive zero aggregated scores before background-channel processing.

  • Constant: uniform weights, giving an arithmetic mean of overlapping predictions.
  • Gaussian: spatially varying weights that favor predictions near patch centers.
Constant blending
overlap: 0.75
blending_mode: constant
blending_sigma: 0
Gaussian blending
overlap: 0.75
blending_mode: gaussian
blending_sigma: null

The recommended mode is overlap: 0.75 and blending_mode: constant.

Artifact classes

GrandQC performs pixel-wise classification of tissue and artifacts.

  • Artifact-free tissue

    Artifact-free tissue


    Class ID: 1

    RGB: (128, 128, 128)

  • Tissue folds

    Tissue folds


    Class ID: 2

    RGB: (255, 99, 71)

  • Dark spots

    Dark spots and foreign objects


    Class ID: 3

    RGB: (0, 255, 0)

  • Pen marks

    Pen marks


    Class ID: 4

    RGB: (255, 0, 0)

  • Air bubbles and edges

    Air bubbles and edges


    Class ID: 5

    RGB: (255, 0, 255)

  • Out-of-focus

    Out-of-focus


    Class ID: 6

    RGB: (75, 0, 130)

Background class

Background regions are visualized in black (RGB: 0, 0, 0).

Outputs and visualizations

Results include label masks (mask), bounding boxes (bbox), optional per-class score maps (raw_mask), magnification metadata, configuration and processing time.

ArtifactOverlayCollector generates a whole-slide overlay by merging masks at vis_mag.

References and acknowledgements

Citation required

If you use GrandQC through HistoKit in your research, please cite both the original GrandQC publication and the pretrained model checkpoints listed below.

We gratefully acknowledge Zhilong Weng, Yuri Tolkach, and all GrandQC contributors for developing the original framework and making the pretrained models available for academic and non-commercial use. HistoKit uses their artifact segmentation model with a modified patch-based inference and aggregation pipeline.

Original GrandQC publication

Weng, Z. et al. (2024). GrandQC: A comprehensive solution to quality control problem in digital pathology. Nature Communications, 15, 10685.

Read the publication | Original repository

BibTeX citation
@article{Weng2024GrandQC,
  author  = {Weng, Zhilong and others},
  title   = {GrandQC: A comprehensive solution to quality control problem in digital pathology},
  journal = {Nature Communications},
  volume  = {15},
  pages   = {10685},
  year    = {2024},
  doi     = {10.1038/s41467-024-54769-y},
  url     = {https://doi.org/10.1038/s41467-024-54769-y}
}

Pretrained model checkpoints

Tolkach, Y., & Weng, Z. (2024). Model checkpoints for GrandQC tool. Zenodo.

Zenodo record | Model checkpoints

BibTeX citation
@misc{Tolkach2024GrandQCCheckpoints,
  author    = {Tolkach, Yuri and Weng, Zhilong},
  title     = {Model checkpoints for GrandQC tool},
  year      = {2024},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.14041538},
  url       = {https://doi.org/10.5281/zenodo.14041538}
}

Source code and licensing

Official GrandQC repository | Original license

Non-commercial use only

The integration of GrandQC into HistoKit does not modify or supersede the original GrandQC licensing terms. Users are responsible for complying with the original license and the applicable restrictions on pretrained model weights.