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 @@ -