-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsaveMeasurementMap.groovy
64 lines (53 loc) · 2.19 KB
/
saveMeasurementMap.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import qupath.lib.gui.tools.MeasurementMapper
import qupath.lib.gui.images.servers.RenderedImageServer
// Define the color map name
String colorMapName = 'Jet'
// Load a color mapper
def colorMapper = MeasurementMapper.loadColorMappers().find {it.name == colorMapName}
println colorMapper
// Define measurement & display range
def name = "Distance to annotation with nothing µm" // Set to null to reset
double minValue = 0.0
double maxValue = 20
// Request current viewer & objects
def viewer = getCurrentViewer()
def options = viewer.getOverlayOptions()
def detections = getDetectionObjects()
// Update the display
if (name) {
print String.format('Setting measurement map: %s (%.2f - %.2f)', name, minValue, maxValue)
def mapper = new MeasurementMapper(colorMapper, name, detections)
mapper.setDisplayMinValue(minValue)
mapper.setDisplayMaxValue(maxValue)
options.setMeasurementMapper(mapper)
} else {
print 'Resetting measurement map'
options.setMeasurementMapper(null)
}
// Now export the rendered image
import qupath.imagej.tools.IJTools
import qupath.lib.gui.images.servers.RenderedImageServer
import qupath.lib.gui.viewer.overlays.HierarchyOverlay
import qupath.lib.regions.RegionRequest
// It is important to define the downsample!
// This is required to determine annotation line thicknesses
double downsample = 1
// Add the output file path here
String path = buildFilePath(PROJECT_BASE_DIR, 'rendered')
mkdirs(path)
// Request the current viewer for settings, and current image (which may be used in batch processing)
def imageData = getCurrentImageData()
// Create a rendered server that includes a hierarchy overlay using the current display settings
def server = new RenderedImageServer.Builder(imageData)
.downsamples(downsample)
.layers(new HierarchyOverlay(null, options, imageData))
.build()
// Write or display the rendered image
int count = 0
for (annotation in getAnnotationObjects()) {
count++
def imageName = getProjectEntry().getImageName() + count + 'dist-nothing.png'
def path2 = buildFilePath(path, imageName)
def region = RegionRequest.createInstance(server.getPath(), downsample, annotation.getROI())
writeImageRegion(server, region, path2)
}