-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_tiles.groovy
36 lines (34 loc) · 1.99 KB
/
export_tiles.groovy
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
import qupath.lib.images.servers.LabeledImageServer
println('Starting export')
def imageData = getCurrentImageData()
// Define output path (relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath(PROJECT_BASE_DIR, 'tiles', name)
mkdirs(pathOutput)
println('Output path:')
println(pathOutput)
// Define output resolution
double requestedPixelSize = 0.25
// Convert to downsample
double downsample = requestedPixelSize / imageData.getServer().getPixelCalibration().getAveragedPixelSize()
println('Downsample:')
println(downsample)
// Create an ImageServer where the pixels are derived from annotations
def labelServer = new LabeledImageServer.Builder(imageData)
.backgroundLabel(0, ColorTools.WHITE) // Specify background label (usually 0 or 255)
.downsample(downsample) // Choose server resolution; this should match the resolution at which tiles are exported
.addLabel('Tumor', 1) // Choose output labels (the order matters!)
.multichannelOutput(false) // If true, each label is a different channel (required for multiclass probability)
.build()
println('labelServer built')
// Create an exporter that requests corresponding tiles from the original & labeled 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')
.labeledImageExtension('.png') // Define file extension for annotation pixels
.tileSize(1024) // Define size of each tile, in pixels
.labeledServer(labelServer) // Define the labeled image server to use (i.e. the one we just built)
.annotatedTilesOnly(true) // If true, only export tiles if there is a (labeled) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
println('Done!')