Search in sources :

Example 6 with PathObjects

use of qupath.lib.objects.PathObjects in project qupath by qupath.

the class PointIOTest method test2ReadPoints.

@Test
public void test2ReadPoints() {
    List<PathObject> pathObjects = null;
    List<Double[]> pointsList = new ArrayList<>();
    try {
        pathObjects = PointIO.readPoints(file);
        for (var pathObject : pathObjects) {
            Point2 point = pathObject.getROI().getAllPoints().get(0);
            pointsList.add(new Double[] { point.getX(), point.getY() });
        }
    } catch (IOException e) {
        fail();
    }
    // Check that we have the same number of sets as originally
    assertTrue(pathObjects.size() == 5);
    // Check that all coordinates are the same
    assertTrue(map.values().stream().allMatch(p -> {
        return Arrays.stream(p).anyMatch(o -> pointsList.stream().anyMatch(m -> Arrays.equals(m, o)));
    }));
    // Check that classes were correctly assigned (Sets 3 & 5)
    assertTrue(pathObjects.stream().filter(p -> isInside(map.get(3), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getPathClass().getName().equals("Other")));
    assertTrue(pathObjects.stream().filter(p -> isInside(map.get(5), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getPathClass().getName().equals("Tumor")));
    // Check that name were correctly assigned (Sets 4 & 5)
    assertTrue(pathObjects.stream().filter(p -> isInside(map.get(4), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getName().equals("foo")));
    assertTrue(pathObjects.stream().filter(p -> isInside(map.get(5), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getName().equals("bar")));
    // Check C, Z and T
    assertTrue(pathObjects.stream().allMatch(q -> {
        if (isInside(map.get(2), q.getROI().getAllPoints().get(0)))
            return (q.getROI().getC() == 2 && q.getROI().getZ() == 1 && q.getROI().getT() == 7);
        else
            return (q.getROI().getC() == -1 && q.getROI().getZ() == 0 && q.getROI().getT() == 0);
    }));
    file.delete();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Arrays(java.util.Arrays) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) PathObjects(qupath.lib.objects.PathObjects) IOException(java.io.IOException) HashMap(java.util.HashMap) PathClassFactory(qupath.lib.objects.classes.PathClassFactory) File(java.io.File) ArrayList(java.util.ArrayList) MethodOrderer(org.junit.jupiter.api.MethodOrderer) PathObject(qupath.lib.objects.PathObject) Test(org.junit.jupiter.api.Test) ROI(qupath.lib.roi.interfaces.ROI) ROIs(qupath.lib.roi.ROIs) List(java.util.List) Point2(qupath.lib.geom.Point2) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) ImagePlane(qupath.lib.regions.ImagePlane) PathObject(qupath.lib.objects.PathObject) Point2(qupath.lib.geom.Point2) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 7 with PathObjects

use of qupath.lib.objects.PathObjects in project qupath by qupath.

the class Commands method promptToSimplifySelectedAnnotations.

/**
 * Show a prompt to selected annotations in a hierarchy.
 * @param imageData the current image data
 * @param altitudeThreshold default altitude value for simplification
 */
public static void promptToSimplifySelectedAnnotations(ImageData<?> imageData, double altitudeThreshold) {
    PathObjectHierarchy hierarchy = imageData.getHierarchy();
    List<PathObject> pathObjects = hierarchy.getSelectionModel().getSelectedObjects().stream().filter(p -> p.isAnnotation() && p.hasROI() && p.isEditable() && !p.getROI().isPoint()).collect(Collectors.toList());
    if (pathObjects.isEmpty()) {
        Dialogs.showErrorMessage("Simplify annotations", "No unlocked shape annotations selected!");
        return;
    }
    String input = Dialogs.showInputDialog("Simplify shape", "Set altitude threshold in pixels.\nHigher values give simpler shapes.", Double.toString(altitudeThreshold));
    if (input == null || !(input instanceof String) || ((String) input).trim().length() == 0)
        return;
    try {
        altitudeThreshold = Double.parseDouble(((String) input).trim());
    } catch (NumberFormatException e) {
        logger.error("Could not parse altitude threshold from {}", input);
        return;
    }
    if (altitudeThreshold <= 0) {
        Dialogs.showErrorMessage("Simplify shape", "Amplitude threshold should be greater than zero!");
        return;
    }
    long startTime = System.currentTimeMillis();
    for (var pathObject : pathObjects) {
        ROI pathROI = pathObject.getROI();
        if (pathROI instanceof PolygonROI) {
            PolygonROI polygonROI = (PolygonROI) pathROI;
            pathROI = ShapeSimplifier.simplifyPolygon(polygonROI, altitudeThreshold);
        } else {
            pathROI = ShapeSimplifier.simplifyShape(pathROI, altitudeThreshold);
        }
        ((PathAnnotationObject) pathObject).setROI(pathROI);
    }
    long endTime = System.currentTimeMillis();
    logger.debug("Shapes simplified in " + (endTime - startTime) + " ms");
    hierarchy.fireObjectsChangedEvent(hierarchy, pathObjects);
}
Also used : Arrays(java.util.Arrays) ServerTools(qupath.lib.images.servers.ServerTools) PathTileObject(qupath.lib.objects.PathTileObject) StackPane(javafx.scene.layout.StackPane) ImageWriter(qupath.lib.images.writers.ImageWriter) ParameterList(qupath.lib.plugins.parameters.ParameterList) ImageRegion(qupath.lib.regions.ImageRegion) Map(java.util.Map) PathObjects(qupath.lib.objects.PathObjects) Screen(javafx.stage.Screen) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) Project(qupath.lib.projects.Project) ShapeFeatures(qupath.lib.analysis.features.ObjectMeasurements.ShapeFeatures) MeasurementMapPane(qupath.lib.gui.panes.MeasurementMapPane) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) RectangleROI(qupath.lib.roi.RectangleROI) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) Supplier(java.util.function.Supplier) Bindings(javafx.beans.binding.Bindings) ViewTrackerControlPane(qupath.lib.gui.viewer.recording.ViewTrackerControlPane) Projects(qupath.lib.projects.Projects) ArrayList(java.util.ArrayList) CheckListView(org.controlsfx.control.CheckListView) ROIs(qupath.lib.roi.ROIs) ShapeSimplifier(qupath.lib.roi.ShapeSimplifier) TextAlignment(javafx.scene.text.TextAlignment) PathClassPane(qupath.lib.gui.panes.PathClassPane) GridPane(javafx.scene.layout.GridPane) Files(java.nio.file.Files) GeneralTools(qupath.lib.common.GeneralTools) RegionRequest(qupath.lib.regions.RegionRequest) Window(java.awt.Window) DistanceTools(qupath.lib.analysis.DistanceTools) IOException(java.io.IOException) File(java.io.File) OverlayOptions(qupath.lib.gui.viewer.OverlayOptions) PathObjectTools(qupath.lib.objects.PathObjectTools) ROI(qupath.lib.roi.interfaces.ROI) QP(qupath.lib.scripting.QP) GridLines(qupath.lib.gui.viewer.GridLines) PathPrefs(qupath.lib.gui.prefs.PathPrefs) RenderedImageServer(qupath.lib.gui.images.servers.RenderedImageServer) PaneTools(qupath.lib.gui.tools.PaneTools) PathIO(qupath.lib.io.PathIO) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) ImageServer(qupath.lib.images.servers.ImageServer) CombineOp(qupath.lib.roi.RoiTools.CombineOp) LoggerFactory(org.slf4j.LoggerFactory) ObservableDoubleValue(javafx.beans.value.ObservableDoubleValue) ComboBox(javafx.scene.control.ComboBox) ImageServers(qupath.lib.images.servers.ImageServers) PolygonROI(qupath.lib.roi.PolygonROI) QuPathGUI(qupath.lib.gui.QuPathGUI) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) PathDetectionObject(qupath.lib.objects.PathDetectionObject) PathObject(qupath.lib.objects.PathObject) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer) Priority(javafx.scene.layout.Priority) List(java.util.List) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) ProjectIO(qupath.lib.projects.ProjectIO) GuiTools(qupath.lib.gui.tools.GuiTools) TMASummaryViewer(qupath.lib.gui.tma.TMASummaryViewer) ImagePlane(qupath.lib.regions.ImagePlane) PathCellObject(qupath.lib.objects.PathCellObject) Scene(javafx.scene.Scene) WorkflowCommandLogView(qupath.lib.gui.panes.WorkflowCommandLogView) TextArea(javafx.scene.control.TextArea) ButtonType(javafx.scene.control.ButtonType) Action(org.controlsfx.control.action.Action) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) Function(java.util.function.Function) Dialogs(qupath.lib.gui.dialogs.Dialogs) Insets(javafx.geometry.Insets) ActionTools(qupath.lib.gui.ActionTools) Tooltip(javafx.scene.control.Tooltip) WeakHashMap(java.util.WeakHashMap) ImageData(qupath.lib.images.ImageData) RoiTools(qupath.lib.roi.RoiTools) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) ImageWriterTools(qupath.lib.images.writers.ImageWriterTools) TMACoreObject(qupath.lib.objects.TMACoreObject) Stage(javafx.stage.Stage) Collections(java.util.Collections) ContentDisplay(javafx.scene.control.ContentDisplay) DialogButton(qupath.lib.gui.dialogs.Dialogs.DialogButton) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) PolygonROI(qupath.lib.roi.PolygonROI) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) PathObject(qupath.lib.objects.PathObject) RectangleROI(qupath.lib.roi.RectangleROI) ROI(qupath.lib.roi.interfaces.ROI) PolygonROI(qupath.lib.roi.PolygonROI)

Aggregations

IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Arrays (java.util.Arrays)7 List (java.util.List)7 Map (java.util.Map)7 PathObject (qupath.lib.objects.PathObject)7 PathObjects (qupath.lib.objects.PathObjects)7 ImagePlane (qupath.lib.regions.ImagePlane)7 Collection (java.util.Collection)6 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 ImageData (qupath.lib.images.ImageData)6 ImageServer (qupath.lib.images.servers.ImageServer)6 PathObjectTools (qupath.lib.objects.PathObjectTools)6 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)6 BufferedImage (java.awt.image.BufferedImage)5 File (java.io.File)5 HashMap (java.util.HashMap)5