I’m trying to write a script to generate tiles from a whole slide image, and I want to have control over which ImageServer I use to read the image. I have taken and very lightly adapted a test script from the QuPath documentation:
// script filename: dumptiles.groovy
import qupath.lib.scripting.QP
// Get the current image (supports 'Run for project')
def imageData = getCurrentImageData()
def name = GeneralTools.getNameWithoutExtension(imageData.getServer()
.getMetadata().getName())
// Define output path (here, relative to project)
def pathOutput = buildFilePath('/tmp/QuPath-test', 'tiles', name)
mkdirs(pathOutput)
// Define output resolution in calibrated units (e.g. µm if available)
double requestedPixelSize = 5.0
// Convert output resolution to a downsample factor
double pixelSize = imageData.getServer().getPixelCalibration()
.getAveragedPixelSize()
double downsample = requestedPixelSize / pixelSize
// Create an exporter that requests corresponding tiles from the
// original & labelled image servers
new TileExporter(imageData)
.downsample(downsample) // Define export resolution
.imageExtension('.tif') // Define file extension for original pixels
// (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(512) // Define size of each tile, in pixels
.annotatedTilesOnly(false) // If true, only export tiles if there is a
// (classified) annotation present
.overlap(64) // Define overlap, in pixel units at the
// export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
println 'Done!'
I would then call this script using the command line:
QuPath-0.2.3 script -i /path/to/imagefile.svs dumptiles.groovy
Since this is not part of a QuPath project, there is no prior specification of the Server type so QuPath has to make the decision. I haven’t been able to yet figure out how to specify this in a script (similar to what one would do in the GUI frontend when importing an image and selecting the Image provider).
Any pointers would be gratefully appreciated!
Thanks