Class QPEx

java.lang.Object
qupath.lib.scripting.QP
qupath.lib.gui.scripting.QPEx

public class QPEx extends QP
Alternative to QP offering static methods of use for scripting, along with some extra methods that require access of GUI features.
Author:
Pete Bankhead
  • Constructor Details

    • QPEx

      public QPEx()
  • Method Details

    • getCoreClasses

      public static Collection<Class<?>> 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

      public static void exportTMAData(String path, double downsampleFactor) throws IOException
      Export TMA summary data for the current image.
      Parameters:
      path - path to the export directory
      downsampleFactor - 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 export
      path - path to the export directory
      downsampleFactor - downsample applied to each TMA core image
      Throws:
      IOException
    • getQuPath

      public static QuPathGUI getQuPath()
      Get the current QuPath instance.
      Returns:
    • getCurrentViewer

      public static QuPathViewer 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

      public static String locateFile(String nameOrPath) throws IOException
      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

      public static String locateFile(String nameOrPath, int searchDepth) throws IOException
      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 path
      searchDepth - 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

      public static boolean runPlugin(String className, String args) throws InterruptedException
      Throws:
      InterruptedException
    • createTaskRunner

      public static TaskRunner createTaskRunner()
      Create a task runner with the default number of threads defined by ThreadTools.getParallelism(). This will either be interactive (if QuPath is running, and the current image is open or headless.
      Returns:
    • createTaskRunner

      public static TaskRunner createTaskRunner(int nThreads)
      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

      public static File promptForFile(String... extensions)
      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

      public static void writeRenderedImage(QuPathViewer viewer, String path) throws IOException
      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

      public static void writeImage(Image image, String path) throws IOException
      Write a JavaFX image to the specified path.
      Parameters:
      image - the image to write
      path - 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 current ImageData 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 specified ImageData 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

      public static void setChannelDisplayRange(String channelName, double minDisplay, double maxDisplay)
      Set the minimum and maximum display range for the current ImageData 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 specified ImageData for a channel identified by name.
      Parameters:
      imageData -
      channelName -
      minDisplay -
      maxDisplay -
    • saveAnnotationMeasurements

      public static void saveAnnotationMeasurements(String path, String... includeColumns)
      Save annotation measurements for the current image.
      Parameters:
      path - file path describing where to write the results
      includeColumns - specific columns to include, or empty to indicate that all measurements should be exported
    • saveTMAMeasurements

      public static void saveTMAMeasurements(String path, String... includeColumns)
      Save TMA measurements for the current image.
      Parameters:
      path - file path describing where to write the results
      includeColumns - specific columns to include, or empty to indicate that all measurements should be exported
    • saveDetectionMeasurements

      public static void saveDetectionMeasurements(String path, String... includeColumns)
      Save detection measurements for the current image.
      Parameters:
      path - file path describing where to write the results
      includeColumns - specific columns to include, or empty to indicate that all measurements should be exported
    • saveImageMeasurements

      public static void saveImageMeasurements(String path, String... includeColumns)
      Save whole image measurements for the current image.
      Parameters:
      path - file path describing where to write the results
      includeColumns - 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 data
      path - file path describing where to write the results
      includeColumns - 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 data
      path - file path describing where to write the results
      includeColumns - 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 data
      path - file path describing where to write the results
      includeColumns - 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 data
      path - file path describing where to write the results
      includeColumns - 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 measure
      path - file path describing where to write the results
      includeColumns - 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 data
      type - the type of objects to measure
      path - file path describing where to write the results
      includeColumns - specific columns to include, or empty to indicate that all measurements should be exported
    • getWindow

      public static Window getWindow(String title)
      Access a window currently open within QuPath by its title.
      Parameters:
      title -
      Returns:
    • copyToClipboard

      public static void copyToClipboard(Object o)
      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

      public static ImageDisplaySettings loadDisplaySettings(String name)
      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

      public static boolean applyDisplaySettings(String name)
      Apply the display settings with the specified name or file path to the current version. This provides a convenient alternative to

      
       var settings = loadDisplaySettings(name);
       var viewer = getCurrentViewer();
       if (settings != null)
           applyDisplaySettings(viewer, settings);
       
       
      Parameters:
      name -
      Returns:
      See Also:
    • applyDisplaySettings

      public static boolean applyDisplaySettings(ImageDisplaySettings settings)
      Apply the display settings to the current viewer.
      Parameters:
      settings -
      Returns:
    • applyDisplaySettings

      public static boolean applyDisplaySettings(QuPathViewer viewer, ImageDisplaySettings settings)
      Apply the display settings to the specified viewer.
      Parameters:
      viewer -
      settings -
      Returns: