The pipeline begins with an input whole-slide image (WSI), followed by a quality assessment (QA) stage that identifies and retains high-quality tissue tiles while excluding low-quality regions affected by artifacts, blur, background, or insufficient tissue content. The selected tiles are then processed using one of 12 color normalization methods, including traditional approaches (Ruifrok, Vahadane, Histogram Matching, Mean-Std, Macenko, Reinhard, and Multi-Macenko) and deep learning-based methods (StainGAN, StainNet, Sastaindiff, CycleGAN, and Pix2Pix), to reduce stain variability and improve color consistency. The resulting normalized images provide standardized inputs for a wide range of deep learning-based computational pathology tasks, such as nuclei detection, segmentation, classification, and quantitative analysis.
This pipeline consists of two sequential steps designed to generate high-quality, standardized H&E image tiles for downstream deep learning applications.
The quality assessment model is first applied WSI-SmartTiling or WSI-QA to the whole-slide images (WSIs) to identify and remove low-quality regions (e.g., background, blur, artifacts, or out-of-focus areas). Only high-quality tissue tiles are retained and exported for the next preprocessing stage.
The retained image tiles are then processed using the color normalization pipeline provided in this repository. This step reduces stain and color variability across H&E images, producing standardized image tiles that can be directly used for downstream tasks such as nuclei detection, segmentation, classification, and quantitative analysis.
- System requirements:
- Ubuntu >= 20.04
- CUDA version >= 12.2
- Python version >= 3.9
- Anaconda version >= 23.7.4
- QA:
- For WSI quality assessment and tile generation, refer to WSI-SmartTiling
- ColorNorm:
- Clone the repo
git clone https://github.com/Falah-Jabar-Rahim/WSI-QCN.git
cd WSI-QCN- Create the conda environment
conda create -n WSI-QCN python=3.10
conda activate WSI-QCN
pip install -r requirements.txt
Note: PyTorch version should matches your CUDA driver. Check your CUDA version with nvidia-smi, then follow the official installation guide
- Verify Installation
- Run the following command to verify that all dependencies have been installed correctly:
python test_installation.py
| name | mode | framework | needs a target/reference | needs a checkpoint |
|---|---|---|---|---|
ruifrok |
sequential | numpy | yes (target) |
no |
vahadane |
sequential | numpy | yes (target) |
no |
histogram_matching |
sequential | numpy | yes (target) |
no |
mean_std |
sequential | numpy | no | no |
macenko |
sequential | torch | yes (target) |
no |
reinhard |
sequential | torch | yes (target) |
no |
multi_macenko |
sequential | torch | yes (targets) |
no |
staingan |
batch | torch | no | yes |
stainnet |
batch | torch | no | yes |
sastaindiff |
batch | torch | no | yes |
cyclegan |
batch | tensorflow | no | yes |
densepix2pix |
batch | tensorflow | no | yes |
Run python main.py --list to see this from the CLI, with each method's mode. The input tile dimensions should be divisible by 2; otherwise, some deep-learning methods may not work correctly.
The pretrained model checkpoints are available on Hugging Face: WSI-QCN Checkpoints
Download the required checkpoint files and place them in the corresponding directories:
WSI-QCN/
├── methods/
│ ├── GanStainNorm/
│ │ └── checkpoints/
│ ├── SAStainDiff/
│ │ └── checkpoint/
│ └── StainNet/
│ └── checkpoints/
Ensure that each checkpoint is copied into the appropriate folder before running the pipeline.
- Input images: Place your input images in
data/input/<your_folder>/, then setsource_directoryinmain.pyor specify the folder using the--input-dirargument. - Reference (target) images: For stain normalization methods that require a reference image (
ruifrok,vahadane,histogram_matching,macenko, andreinhard), place the reference image(s) indata/reference/.
Run everything:
python main.py
Run one method:
python main.py --method stainnet
List available methods:
python main.py --list
Override the batch size (batch-capable methods only - ignored for sequential ones):
python main.py --method sastaindiff --batch-size 2
Override input/output folders:
python main.py --input-dir data/input/my_images --output-dir results/run_1
Combine as needed:
python main.py --method all --batch-size 8 --input-dir data/input/test_set
Each method writes to its own subfolder, so the same image can be compared across methods:
results/
macenko_torch/img001.png
stainnet/img001.png
cyclegan/img001.png
...
TBD
If you have any questions or comments, please feel free to contact: [email protected]
