Triggered by the post
I create the following short script to prepare the current image entry for a 3-stain color deconvolution and assign custom stain vectors:
// **************************************************************************
// File : Setup3ColorDeconvolution.groovy
//
// Author: Peter Haub
// March 2021
// Copyright (C) 2021 Peter Haub
//
// This script prepares a brightfield image for 3 color deconvolution with customized stain vectors.
// **************************************************************************
import qupath.lib.color.ColorDeconvolutionStains
import qupath.lib.color.StainVector
import qupath.lib.gui.QuPathGUI
import qupath.lib.gui.viewer.QuPathViewer
import qupath.lib.images.ImageData
import qupath.lib.gui.scripting.QPEx
QuPathViewer viewer = QuPathGUI.getInstance().getViewer()
def imageData = QPEx.getCurrentViewer().getImageData()
imageData.setImageType(ImageData.ImageType.BRIGHTFIELD_OTHER)
// Customize your 3 stains here (vector will be normalized)
StainVector stain1 = StainVector.createStainVector("Stain1", 0.7110, 0.6300, 0.3080)
StainVector stain2 = StainVector.createStainVector("Stain2", 0.3250, 0.6070, 0.7250)
StainVector stain3 = StainVector.createStainVector("Stain3", 0.3000, 0.9100, 0.2850)
// Customize your RGB background values here
double maxR = 255
double maxG = 255
double maxB = 255
ColorDeconvolutionStains stains = new ColorDeconvolutionStains("CustomStains", stain1, stain2, stain3, maxR, maxG, maxB)
imageData.setColorDeconvolutionStains(stains)
viewer.repaintEntireImage()
println('Done!')
Here is the output for the test image from the post mentioned above: