@ahouston Something like this should be close:
import qupath.lib.gui.tools.MeasurementMapper
import qupath.lib.gui.images.servers.RenderedImageServer
// Define the color map name
String colorMapName = 'Magma'
// Load a color mapper
def colorMapper = MeasurementMapper.loadColorMappers().find {it.name == colorMapName}
println colorMapper
// Define measurement & display range
def name = "Nucleus: Circularity" // Set to null to reset
double minValue = 0.0
double maxValue = 1.0
// 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 = 10
// 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 + '.png'
def path2 = buildFilePath(path, imageName)
def region = RegionRequest.createInstance(server.getPath(), downsample, annotation.getROI())
writeImageRegion(server, region, path2)
}
It’s a bit ugly, since it’s really two scripts glued together and tweaked a little bit. The originals are
Be sure to look out for the name
, colorMapName
and downsample
values, which probably will need to be changed.
This works using Run for project, but you might be able to drop the whole first half of the script if you set the measurement mapper in the viewer manually.