Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Fix qupath#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.
  • Loading branch information
petebankhead committed Nov 13, 2023
1 parent c88101e commit 7fb6ae0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/main/java/qupath/ext/wsinfer/TileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/qupath/ext/wsinfer/ui/WSInferController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</Button>
</children>
</HBox>
<Label id="labelWarning" fx:id="labelMessage" prefHeight="30.0" styleClass="error-message" text="%ui.error.no-selection" VBox.vgrow="ALWAYS" />
<Label id="labelWarning" fx:id="labelMessage" styleClass="error-message" text="%ui.error.no-selection" VBox.vgrow="ALWAYS" />
<styleClass>
<String fx:value="standard-spacing" />
<String fx:value="standard-padding" />
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/qupath/ext/wsinfer/ui/wsinferstyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}

.standard-padding {
-fx-padding: 4;
-fx-padding: 2;
}

/*download button*/
Expand Down

0 comments on commit 7fb6ae0

Please sign in to comment.