-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tile_from_annotation.groovy
33 lines (27 loc) · 1.51 KB
/
create_tile_from_annotation.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
/**
* Script to export image tiles (can be customized in various ways).
*/
// Get the current image (supports 'Run for project')
def imageData = getCurrentImageData()
// Define output path (here, relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath(PROJECT_BASE_DIR, 'tiles', name)
mkdirs(pathOutput)
// Define output resolution in calibrated units (e.g. µm if available)
double requestedPixelSize = 1 //only use t his if image is same DPI
//otherwise use direct downsample
double downsample= 1
// 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
.includePartialTiles(false)
.imageExtension('.png') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(224) // Define size of each tile, in pixels
.annotatedCentroidTilesOnly(true) // exclude white tiles
.annotatedTilesOnly(true) // If true, only export tiles if there is a (classified) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
print 'Done!'