Package qupath.lib.gui.scripting
Class QPEx
java.lang.Object
qupath.lib.scripting.QP
qupath.lib.gui.scripting.QPEx
Alternative to QP offering static methods of use for scripting,
along with some extra methods that require access of GUI features.
- Author:
- Pete Bankhead
-
Field Summary
Fields inherited from class qupath.lib.scripting.QP
BRIGHTFIELD_H_DAB, BRIGHTFIELD_H_E, BRIGHTFIELD_OTHER, FLUORESCENCE, OTHER, PROJECT_BASE_DIR, VERSION
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
applyDisplaySettings
(String name) Apply the display settings with the specified name or file path to the current version.static boolean
applyDisplaySettings
(ImageDisplaySettings settings) Apply the display settings to the current viewer.static boolean
applyDisplaySettings
(QuPathViewer viewer, ImageDisplaySettings settings) Apply the display settings to the specified viewer.static void
Try to copy an object to the clipboard.static TaskRunner
Create a task runner with the default number of threads defined byThreadTools.getParallelism()
.static TaskRunner
createTaskRunner
(int nThreads) Create a task runner with the specified number of threads.static void
exportTMAData
(String path, double downsampleFactor) Export TMA summary data for the current image.static void
exportTMAData
(ImageData<BufferedImage> imageData, String path, double downsampleFactor) Export TMA summary data for the specified image.static Collection
<Class<?>> Get a list of core classes that are likely to be useful for scripting.static QuPathViewer
Get the active viewer in the current QuPath instance.static QuPathGUI
Get the current QuPath instance.static Window
Access a window currently open within QuPath by its title.static ImageDisplaySettings
loadDisplaySettings
(String name) Load a display settings object from a file path or from the current project.static String
locateFile
(String nameOrPath) Locate a specified file based upon its name or path, with a search depth of 4.static String
locateFile
(String nameOrPath, int searchDepth) Locate a specified file based upon its name or path.static File
promptForFile
(String... extensions) Prompt the user to select a file from a file chooser.static boolean
static boolean
static void
saveAnnotationMeasurements
(String path, String... includeColumns) Save annotation measurements for the current image.static void
saveAnnotationMeasurements
(ImageData<?> imageData, String path, String... includeColumns) Save annotation measurements for the specified image.static void
saveDetectionMeasurements
(String path, String... includeColumns) Save detection measurements for the current image.static void
saveDetectionMeasurements
(ImageData<?> imageData, String path, String... includeColumns) Save detection measurements for the specified image.static void
saveImageMeasurements
(String path, String... includeColumns) Save whole image measurements for the current image.static void
saveImageMeasurements
(ImageData<?> imageData, String path, String... includeColumns) Save whole image measurements for the specified image.static void
saveMeasurements
(Class<? extends PathObject> type, String path, String... includeColumns) Save measurements for the current image for objects of a fixed type.static void
saveMeasurements
(ImageData<?> imageData, Class<? extends PathObject> type, String path, String... includeColumns) Save measurements for the specified image for objects of a fixed type.static void
saveTMAMeasurements
(String path, String... includeColumns) Save TMA measurements for the current image.static void
saveTMAMeasurements
(ImageData<?> imageData, String path, String... includeColumns) Save TMA measurements for the specified image.static void
setChannelDisplayRange
(int channel, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the currentImageData
for a channel identified by number.static void
setChannelDisplayRange
(String channelName, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the currentImageData
for a channel identified by name.static boolean
setChannelDisplayRange
(ImageData<BufferedImage> imageData, int channel, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the specifiedImageData
for a channel identified by number.static void
setChannelDisplayRange
(ImageData<BufferedImage> imageData, String channelName, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the specifiedImageData
for a channel identified by name.static void
writeImage
(Image image, String path) Write a JavaFX image to the specified path.static void
writeRenderedImage
(QuPathViewer viewer, String path) Write a rendered image for the current viewer to the specified path.static void
writeRenderedImage
(ImageData<BufferedImage> imageData, String path) Write a rendered image to the specified path.static void
writeRenderedImageRegion
(QuPathViewer viewer, RegionRequest request, String path) Write a rendered image region for the current viewer to the specified path.static void
writeRenderedImageRegion
(ImageData<BufferedImage> imageData, RegionRequest request, String path) Write a rendered image region to the specified path.Methods inherited from class qupath.lib.scripting.QP
addObject, addObjects, addObjects, addPixelClassifierMeasurements, addPixelClassifierMeasurements, addShapeMeasurements, addShapeMeasurements, addShapeMeasurements, buildFilePath, buildPathInProject, buildServer, buildServer, buildServer, checkMinVersion, checkVersionRange, classifyDetectionsByCentroid, classifyDetectionsByCentroid, classifySelected, classifySelected, clearAllObjects, clearAllObjects, clearAnnotationMeasurements, clearAnnotationMeasurements, clearAnnotations, clearCellMeasurements, clearCellMeasurements, clearDetectionMeasurements, clearDetectionMeasurements, clearDetections, clearMeasurements, clearMeasurements, clearMeasurements, clearMeasurements, clearMeasurements, clearRootMeasurements, clearRootMeasurements, clearSelectedObjects, clearSelectedObjects, clearTileMeasurements, clearTileMeasurements, clearTMACoreMeasurements, clearTMACoreMeasurements, clearTMAGrid, copySelectedAnnotationsToPlane, copySelectedAnnotationsToPlane, copySelectedAnnotationsToPlane, copySelectedObjectsToPlane, copySelectedObjectsToPlane, copySelectedObjectsToPlane, createAllFullImageAnnotations, createAllFullImageAnnotations, createAnnotationsFromDensityMap, createAnnotationsFromDensityMap, createAnnotationsFromDensityMap, createAnnotationsFromPixelClassifier, createAnnotationsFromPixelClassifier, createDetectionsFromPixelClassifier, createDetectionsFromPixelClassifier, createFullImageAnnotation, createFullImageAnnotation, createFullImageAnnotation, createFullImageAnnotation, createSelectAllObject, createSelectAllObject, createTMAGrid, createTMAGrid, describe, describe, deselectAll, deselectAll, detectionCentroidDistances, detectionCentroidDistances, detectionCentroidDistances, detectionToAnnotationDistances, detectionToAnnotationDistances, detectionToAnnotationDistances, detectionToAnnotationDistancesSigned, detectionToAnnotationDistancesSigned, duplicateSelectedAnnotations, duplicateSelectedAnnotations, exportAllObjectsToGeoJson, exportAllObjectsToGeoJson, exportObjectsToGeoJson, exportObjectsToGeoJson, exportSelectedObjectsToGeoJson, exportSelectedObjectsToGeoJson, fileExists, findDensityMapHotspots, findDensityMapHotspots, findDensityMapHotspots, fireHierarchyUpdate, fireHierarchyUpdate, getAllObjects, getAllObjects, getAnnotationObjects, getBasePathClass, getCellObjects, getColorRGB, getCurrentHierarchy, getCurrentImageData, getCurrentImageName, getCurrentImageNameWithoutExtension, getCurrentServer, getCurrentServerPath, getDerivedPathClass, getDerivedPathClass, getDetectionObjects, getLogger, getNonIntensityAncestorPathClass, getObjects, getObjects, getPathClass, getPathClass, getProject, getProjectEntry, getProjectEntryMetadataValue, getSelectedObject, getSelectedObjects, getSelectedROI, getTileObjects, getTMACoreList, hasMeasurement, importObjectsFromFile, insertObjects, insertObjects, isDirectory, isTMADearrayed, loadDensityMap, loadImageData, loadObjectClassifier, loadPixelClassifier, makeARGB, makeFileInProject, makeInverseAnnotation, makeInverseAnnotation, makeInverseAnnotation, makeInverseAnnotation, makeInverseAnnotation, makePathInProject, makeRGB, measurement, mergeAnnotations, mergeAnnotations, mergePointsForAllClasses, mergePointsForSelectedObjectClasses, mergeSelectedAnnotations, mergeSelectedAnnotations, mkdirs, nObjects, refreshDuplicateIDs, refreshDuplicateIDs, refreshIDs, refreshIDs, relabelTMAGrid, relabelTMAGrid, removeMeasurements, removeMeasurements, removeObject, removeObjects, removeObjects, removeObjectsOutsideImage, removeObjectsOutsideImage, removeObjectsOutsideImage, removeObjectsOutsideImage, removeOrClipObjectsOutsideImage, removeOrClipObjectsOutsideImage, replaceClassification, replaceClassification, replaceClassification, replaceClassification, resetBatchProjectAndImage, resetClassifications, resetClassifications, resetDetectionClassifications, resetIntensityClassifications, resetIntensityClassifications, resetIntensityClassifications, resetSelection, resetTMAMetadata, resetTMAMetadata, resolveHierarchy, resolveHierarchy, resolvePath, runObjectClassifier, runObjectClassifier, runPlugin, runPlugin, runPlugin, runPlugin, scaleAllObjects, scaleAllObjects, selectAllObjects, selectAllObjects, selectAllObjects, selectAnnotations, selectAnnotations, selectCells, selectCells, selectDetections, selectDetections, selectObjects, selectObjects, selectObjects, selectObjects, selectObjects, selectObjects, selectObjectsByClass, selectObjectsByClass, selectObjectsByClassification, selectObjectsByClassification, selectObjectsByMeasurement, selectObjectsByPathClass, selectObjectsByPathClass, selectObjectsByPlane, selectObjectsByPlane, selectObjectsByPlane, selectTiles, selectTiles, selectTMACores, selectTMACores, selectTMACores, selectTMACores, setBatchProjectAndImage, setCellIntensityClassifications, setCellIntensityClassifications, setChannelColors, setChannelColors, setChannelNames, setChannelNames, setChannels, setChannels, setColorDeconvolutionStains, setDefaultImageData, setDefaultProject, setDetectionIntensityClassifications, setDetectionIntensityClassifications, setImageType, setImageType, setIntensityClassifications, setIntensityClassifications, setIntensityClassifications, setIntensityClassificationsForSelected, setPixelSizeMicrons, setPixelSizeMicrons, setPixelSizeMicrons, setSelectedObject, splitAllAnnotationAreasByLines, splitAllAnnotationAreasByLines, splitAllAnnotationAreasByLines, splitAllAnnotationAreasByLines, splitSelectedAnnotationAreasByLines, splitSelectedAnnotationAreasByLines, splitSelectedAnnotationAreasByLines, splitSelectedAnnotationAreasByLines, splitSpecifiedAreasByLines, transformAllObjects, transformAllObjects, transformSelectedObjects, transformSelectedObjects, translateAllObjects, translateAllObjects, writeDensityMapImage, writeDensityMapImage, writeImage, writeImage, writeImageRegion, writePredictionImage, writePredictionImage
-
Constructor Details
-
QPEx
public QPEx()
-
-
Method Details
-
getCoreClasses
Get a list of core classes that are likely to be useful for scripting. The purpose of this is to allow users to find classes they are likely to need, or to import these automatically at the beginning of scripts.- Returns:
-
exportTMAData
Export TMA summary data for the current image.- Parameters:
path
- path to the export directorydownsampleFactor
- downsample applied to each TMA core image- Throws:
IOException
-
exportTMAData
public static void exportTMAData(ImageData<BufferedImage> imageData, String path, double downsampleFactor) throws IOException Export TMA summary data for the specified image.- Parameters:
imageData
- the image containing TMA data to exportpath
- path to the export directorydownsampleFactor
- downsample applied to each TMA core image- Throws:
IOException
-
getQuPath
Get the current QuPath instance.- Returns:
-
getCurrentViewer
Get the active viewer in the current QuPath instance.- Returns:
- an active viewer, or null if no viewer is active in QuPath currently
-
locateFile
Locate a specified file based upon its name or path, with a search depth of 4. This first checks if the provided path is to a file that already exists. If it is not, then it searches recursively within the current project or user directory (if available) up to a fixed search depth for a file with the same name.- Parameters:
nameOrPath
- the original name or path- Returns:
- the identified file path, or the original file path if no update was found or required
- Throws:
IOException
- See Also:
-
locateFile
Locate a specified file based upon its name or path. This first checks if the provided path is to a file that already exists. If it is not, then it searches recursively within the current project or user directory (if available) up to a specified search depth for a file with the same name.- Parameters:
nameOrPath
- the original name or pathsearchDepth
- how deep to search subdirectories recursively- Returns:
- the identified file path, or the original file path if no update was found or required
- Throws:
IOException
- See Also:
-
runPlugin
public static boolean runPlugin(String className, ImageData<?> imageData, String args) throws InterruptedException - Throws:
InterruptedException
-
runPlugin
- Throws:
InterruptedException
-
createTaskRunner
Create a task runner with the default number of threads defined byThreadTools.getParallelism()
. This will either be interactive (if QuPath is running, and the current image is open or headless.- Returns:
-
createTaskRunner
Create a task runner with the specified number of threads. This will either be interactive (if QuPath is running, and the current image is open or headless.- Parameters:
nThreads
- number of threads for the task runner to use- Returns:
-
promptForFile
Prompt the user to select a file from a file chooser.- Parameters:
extensions
- valid file extensions, or null if any file may be chosen.- Returns:
- the file chosen by the user, or null if the dialog was cancelled
-
writeRenderedImage
public static void writeRenderedImage(ImageData<BufferedImage> imageData, String path) throws IOException Write a rendered image to the specified path. No overlay layers will be included.- Parameters:
imageData
-path
-- Throws:
IOException
- See Also:
-
writeRenderedImage
Write a rendered image for the current viewer to the specified path.- Parameters:
viewer
-path
-- Throws:
IOException
- See Also:
-
writeRenderedImageRegion
public static void writeRenderedImageRegion(ImageData<BufferedImage> imageData, RegionRequest request, String path) throws IOException Write a rendered image region to the specified path. No overlay layers will be included.- Parameters:
imageData
-request
-path
-- Throws:
IOException
- See Also:
-
writeRenderedImageRegion
public static void writeRenderedImageRegion(QuPathViewer viewer, RegionRequest request, String path) throws IOException Write a rendered image region for the current viewer to the specified path.- Parameters:
viewer
-request
-path
-- Throws:
IOException
- See Also:
-
writeImage
Write a JavaFX image to the specified path.- Parameters:
image
- the image to writepath
- the path to write the image- Throws:
IOException
- See Also:
-
setChannelDisplayRange
public static void setChannelDisplayRange(int channel, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the currentImageData
for a channel identified by number.- Parameters:
channel
- channel number (0-based index)minDisplay
-maxDisplay
-
-
setChannelDisplayRange
public static boolean setChannelDisplayRange(ImageData<BufferedImage> imageData, int channel, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the specifiedImageData
for a channel identified by number.- Parameters:
imageData
-channel
- channel number (0-based index)minDisplay
-maxDisplay
-- Returns:
- true if it was possible to set the display range, false otherwise (e.g. if the image could not be accessed, or the channel was out of range).
-
setChannelDisplayRange
Set the minimum and maximum display range for the currentImageData
for a channel identified by name.- Parameters:
channelName
-minDisplay
-maxDisplay
-
-
setChannelDisplayRange
public static void setChannelDisplayRange(ImageData<BufferedImage> imageData, String channelName, double minDisplay, double maxDisplay) Set the minimum and maximum display range for the specifiedImageData
for a channel identified by name.- Parameters:
imageData
-channelName
-minDisplay
-maxDisplay
-
-
saveAnnotationMeasurements
Save annotation measurements for the current image.- Parameters:
path
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveTMAMeasurements
Save TMA measurements for the current image.- Parameters:
path
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveDetectionMeasurements
Save detection measurements for the current image.- Parameters:
path
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveImageMeasurements
Save whole image measurements for the current image.- Parameters:
path
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveImageMeasurements
public static void saveImageMeasurements(ImageData<?> imageData, String path, String... includeColumns) Save whole image measurements for the specified image.- Parameters:
imageData
- the image datapath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveAnnotationMeasurements
public static void saveAnnotationMeasurements(ImageData<?> imageData, String path, String... includeColumns) Save annotation measurements for the specified image.- Parameters:
imageData
- the image datapath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveTMAMeasurements
public static void saveTMAMeasurements(ImageData<?> imageData, String path, String... includeColumns) Save TMA measurements for the specified image.- Parameters:
imageData
- the image datapath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveDetectionMeasurements
public static void saveDetectionMeasurements(ImageData<?> imageData, String path, String... includeColumns) Save detection measurements for the specified image.- Parameters:
imageData
- the image datapath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveMeasurements
public static void saveMeasurements(Class<? extends PathObject> type, String path, String... includeColumns) Save measurements for the current image for objects of a fixed type.- Parameters:
type
- the type of objects to measurepath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
saveMeasurements
public static void saveMeasurements(ImageData<?> imageData, Class<? extends PathObject> type, String path, String... includeColumns) Save measurements for the specified image for objects of a fixed type.- Parameters:
imageData
- the image datatype
- the type of objects to measurepath
- file path describing where to write the resultsincludeColumns
- specific columns to include, or empty to indicate that all measurements should be exported
-
getWindow
Access a window currently open within QuPath by its title.- Parameters:
title
-- Returns:
-
copyToClipboard
Try to copy an object to the clipboard. This will attempt to perform a smart conversion; for example, if a window is provided a snapshot will be taken and copied as an image.- Parameters:
o
- the object to copy
-
loadDisplaySettings
Load a display settings object from a file path or from the current project.- Parameters:
name
-- Returns:
- the settings if they could be read, or null otherwise
-
applyDisplaySettings
Apply the display settings with the specified name or file path to the current version. This provides a convenient alternative tovar settings = loadDisplaySettings(name); var viewer = getCurrentViewer(); if (settings != null) applyDisplaySettings(viewer, settings);
- Parameters:
name
-- Returns:
- See Also:
-
applyDisplaySettings
Apply the display settings to the current viewer.- Parameters:
settings
-- Returns:
-
applyDisplaySettings
Apply the display settings to the specified viewer.- Parameters:
viewer
-settings
-- Returns:
-