From 7fb6ae0169f285da2629c64f569785531077d2d3 Mon Sep 17 00:00:00 2001 From: Pete Date: Mon, 13 Nov 2023 07:24:54 +0000 Subject: [PATCH] Bug fixes Fix https://github.com/qupath/qupath-extension-wsinfer/issues/45 This uses zero-padding (other padding may be preferable). Also fix threading bug when selected objects are updated from another thread (e.g. a script) and the dialog is showing. Slightly reduce vertical height by reducing padding. --- .../java/qupath/ext/wsinfer/TileLoader.java | 21 +++++++++++++++++-- .../ext/wsinfer/ui/WSInferController.java | 4 ++++ .../ext/wsinfer/ui/wsinfer_control.fxml | 2 +- .../qupath/ext/wsinfer/ui/wsinferstyles.css | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/qupath/ext/wsinfer/TileLoader.java b/src/main/java/qupath/ext/wsinfer/TileLoader.java index b7ceee7..796c783 100644 --- a/src/main/java/qupath/ext/wsinfer/TileLoader.java +++ b/src/main/java/qupath/ext/wsinfer/TileLoader.java @@ -133,9 +133,26 @@ private TileBatch nextBatch() { } else { // Handle normal case of within-bounds coordinates img = server.readRegion(downsample, x, y, width, height); - if (resizeWidth > 0 && resizeHeight > 0) - img = BufferedImageTools.resize(img, resizeWidth, resizeHeight, true); } + if (resizeWidth > 0 && resizeHeight > 0) { + // Using OpenCV is much faster tha BufferedImageTools/ImageJ, + // but using BufferedImageTools (and ImageJ) seems to give more similar results to WSInfer Python. + // For example, using the Python WSInfer 0.5.0 output for the image at + // https://github.com/qupath/qupath-docs/issues/89 (30619 tiles): + // BufferedImageTools Tumor prob Mean Absolute Difference: 0.0026328298250342763 + // OpenCV Tumor prob Mean Absolute Difference: 0.07625036735485102 + // + // Note: If we activate this, then we should handle the if/else above separately to avoid + // regenerating a Mat unnecessarily. +// var mat = OpenCVTools.imageToMat(img); +// var size = new Size(resizeWidth, resizeHeight); +// opencv_imgproc.resize(mat, mat, size, 0, 0, opencv_imgproc.INTER_LINEAR); +// img = OpenCVTools.matToBufferedImage(mat); +// size.close(); +// mat.close(); + img = BufferedImageTools.resize(img, resizeWidth, resizeHeight, true); + } + Image input = BufferedImageFactory.getInstance().fromImage(img); pathObjectBatch.add(pathObject); inputs.add(input); diff --git a/src/main/java/qupath/ext/wsinfer/ui/WSInferController.java b/src/main/java/qupath/ext/wsinfer/ui/WSInferController.java index fc2c44a..ba2b38b 100644 --- a/src/main/java/qupath/ext/wsinfer/ui/WSInferController.java +++ b/src/main/java/qupath/ext/wsinfer/ui/WSInferController.java @@ -694,6 +694,10 @@ private void selectedPathObjectChanged(PathObject pathObjectSelected, PathObject } private void updateSelectedObjectCounts() { + if (!Platform.isFxApplicationThread()) { + Platform.runLater(this::updateSelectedObjectCounts); + return; + } var hierarchy = hierarchyProperty.getValue(); if (hierarchy == null) { numSelectedAnnotations.set(0); diff --git a/src/main/resources/qupath/ext/wsinfer/ui/wsinfer_control.fxml b/src/main/resources/qupath/ext/wsinfer/ui/wsinfer_control.fxml index e7b779d..572c64c 100644 --- a/src/main/resources/qupath/ext/wsinfer/ui/wsinfer_control.fxml +++ b/src/main/resources/qupath/ext/wsinfer/ui/wsinfer_control.fxml @@ -98,7 +98,7 @@ -