Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Last active March 19, 2021 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/3dd03008570ee3e4ae6c449aba209a5d to your computer and use it in GitHub Desktop.
Save petebankhead/3dd03008570ee3e4ae6c449aba209a5d to your computer and use it in GitHub Desktop.
Set a MeasurementMapper in QuPath v0.1.2 to control detection object display in a script
/**
* Set a MeasurementMapper in QuPath v0.2 to control the display in a script.
*
* Revised version of a script for v0.1.2.
*
* @author Pete Bankhead
*/
import qupath.lib.gui.tools.MeasurementMapper
// Define the color map name
String colorMapName = 'Viridis'
// Load a color mapper
def colorMapper = MeasurementMapper.loadColorMappers().find {it.name == colorMapName}
// Define measurement name & 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment