-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path0.5.0 Region Export.groovy
More file actions
28 lines (21 loc) · 918 Bytes
/
0.5.0 Region Export.groovy
File metadata and controls
28 lines (21 loc) · 918 Bytes
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
//Choose Downsample
double downsample = 1 //bigger value = smaller image
//get server
def server = getCurrentServer()
//find existing annotations
def annots = getAnnotationObjects()
//sort and name by location
def annotsX=annots.toSorted{it.getROI().getCentroidX()}
annotsX.eachWithIndex{annot,idx->
annot.setName('Region'+idx.toString())
}
//define the folder the images will be saved to
def folder = buildFilePath(PROJECT_BASE_DIR,'exports')
//if necessary, create it
mkdirs(folder)
annotsX.each { //for each annotation
def roi = it.getROI() //it = current annotation in this round of the loop
def requestROI = RegionRequest.createInstance(server.getPath(), downsample, roi) //get the correct location at the set downsample
def path = buildFilePath(folder, it.getName() + '.tif') //file name will be based on annotation name
writeImageRegion(server, requestROI, path) //write as a tif
}