-
Notifications
You must be signed in to change notification settings - Fork 2
/
geojson_to_qupath.groovy
35 lines (25 loc) · 1.15 KB
/
geojson_to_qupath.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
String annotation_dir = 'D:/ProstateBounds/blad_nuc/geoson_bounds'
boolean use_annotation_dir = true
def server = getCurrentImageData().getServer()
String imgPath = server.getPath()
String path2 = server.getPath()
int ind1 = path2.lastIndexOf('/') + 1
int ind2 = path2.lastIndexOf(".") - 1
name = path2[ind1..ind2]
path = path2[path2.indexOf(File.separator)+1..path2.lastIndexOf("/")-1]
if (use_annotation_dir) {
jsonFilename = annotation_dir + File.separator + name + '_stardist_details.json'
} else {
jsonFilename = path + File.separator + name + '.json'
}
print(use_annotation_dir)
print(jsonFilename)
def gson = GsonTools.getInstance(true)
def json = new File(jsonFilename).text
//println json
// Read the annotations
def type = new com.google.gson.reflect.TypeToken<List<qupath.lib.objects.PathObject>>() {}.getType()
def deserializedAnnotations = gson.fromJson(json, type)
// Set the annotations to have a different name (so we can identify them) & add to the current image
// deserializedAnnotations.eachWithIndex {annotation, i -> annotation.setName('New annotation ' + (i+1))} # --- THIS WON"T WORK IN CURRENT VERSION
addObjects(deserializedAnnotations)