Search in sources :

Example 1 with RunSavedClassifierWorkflowStep

use of qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep in project qupath by qupath.

the class PathClassifierPane method runClassifier.

void runClassifier() {
    QuPathViewer viewer = viewerValue.getValue();
    if (viewer == null)
        return;
    ImageData<BufferedImage> imageData = viewer.getImageData();
    if (classifier == null || imageData == null || !classifier.isValid())
        return;
    Collection<PathObject> pathObjects = imageData.getHierarchy().getDetectionObjects();
    var availableFeatures = PathClassifierTools.getAvailableFeatures(pathObjects);
    var requiredFeatures = classifier.getRequiredMeasurements();
    String missingFeatures = requiredFeatures.stream().filter(p -> !availableFeatures.contains(p)).collect(Collectors.joining("\n\t"));
    if (!missingFeatures.isEmpty())
        logger.warn("Detection objects are missing the following feature(s):\n\t" + missingFeatures + "\nWill proceed with classification anyway..");
    // SwingUtilities.getRoot(viewer).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
        PathClassifierTools.runClassifier(imageData.getHierarchy(), classifier);
        // Log the classifier
        if (pathClassifier != null) {
            imageData.getHistoryWorkflow().addStep(new RunSavedClassifierWorkflowStep(pathClassifier));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // SwingUtilities.getRoot(viewer).setCursor(cursor);
        // Update displayed list - names may have changed - and classifier summary
        updateClassifierSummary();
    }
}
Also used : Button(javafx.scene.control.Button) ImageData(qupath.lib.images.ImageData) RunSavedClassifierWorkflowStep(qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep) PathClassifierTools(qupath.lib.classifiers.PathClassifierTools) Logger(org.slf4j.Logger) TextArea(javafx.scene.control.TextArea) BufferedImage(java.awt.image.BufferedImage) Date(java.util.Date) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) Collectors(java.util.stream.Collectors) File(java.io.File) PathObject(qupath.lib.objects.PathObject) Dialogs(qupath.lib.gui.dialogs.Dialogs) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer) PathObjectClassifier(qupath.lib.classifiers.PathObjectClassifier) ObservableValue(javafx.beans.value.ObservableValue) BorderPane(javafx.scene.layout.BorderPane) GridPane(javafx.scene.layout.GridPane) Pane(javafx.scene.layout.Pane) PaneTools(qupath.lib.gui.tools.PaneTools) PathObject(qupath.lib.objects.PathObject) RunSavedClassifierWorkflowStep(qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep) BufferedImage(java.awt.image.BufferedImage) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer)

Example 2 with RunSavedClassifierWorkflowStep

use of qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep in project qupath by qupath.

the class QP method runClassifier.

/**
 * Run a detection object classifier for the current image data, reading the classifier from a specified path
 * @param path
 */
@Deprecated
public static void runClassifier(final String path) {
    ImageData<?> imageData = getCurrentImageData();
    if (imageData == null)
        return;
    PathObjectClassifier classifier = PathClassifierTools.loadClassifier(new File(path));
    if (classifier == null) {
        logger.error("Could not load classifier from {}", path);
        return;
    }
    runClassifier(imageData, classifier);
    // Log the step
    imageData.getHistoryWorkflow().addStep(new RunSavedClassifierWorkflowStep(path));
}
Also used : PathObjectClassifier(qupath.lib.classifiers.PathObjectClassifier) RunSavedClassifierWorkflowStep(qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep) File(java.io.File)

Aggregations

File (java.io.File)2 PathObjectClassifier (qupath.lib.classifiers.PathObjectClassifier)2 RunSavedClassifierWorkflowStep (qupath.lib.plugins.workflow.RunSavedClassifierWorkflowStep)2 BufferedImage (java.awt.image.BufferedImage)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Collectors (java.util.stream.Collectors)1 ObservableValue (javafx.beans.value.ObservableValue)1 Button (javafx.scene.control.Button)1 TextArea (javafx.scene.control.TextArea)1 BorderPane (javafx.scene.layout.BorderPane)1 GridPane (javafx.scene.layout.GridPane)1 Pane (javafx.scene.layout.Pane)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PathClassifierTools (qupath.lib.classifiers.PathClassifierTools)1 Dialogs (qupath.lib.gui.dialogs.Dialogs)1 PaneTools (qupath.lib.gui.tools.PaneTools)1 QuPathViewer (qupath.lib.gui.viewer.QuPathViewer)1