Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tile padding as an option #70

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegController.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class InstanSegController extends BorderPane {
@FXML
private ChoiceBox<Integer> tileSizeChoiceBox;
@FXML
private ChoiceBox<Integer> tilePaddingChoiceBox;
@FXML
private Spinner<Integer> threadSpinner;
@FXML
private ToggleButton selectAllAnnotationsButton;
Expand Down Expand Up @@ -173,6 +175,7 @@ private InstanSegController(QuPathGUI qupath) throws IOException {

// Options
configureTileSizes();
configureTilePadding();
configureDeviceChoices();
configureThreadSpinner();
configureInputChannelCombo();
Expand Down Expand Up @@ -455,7 +458,7 @@ private void refreshModelChoice() {
var nOutputs = model.getOutputChannels().orElse(1);
comboOutputChannels.getCheckModel().clearChecks();
comboOutputChannels.getItems().setAll(OutputChannelItem.getOutputsForChannelCount(nOutputs));
if (!outputChannelCache.restoreChecks()) {
if (!outputChannelCache.restoreChecks() || comboOutputChannels.getCheckModel().isEmpty()) {
comboOutputChannels.getCheckModel().checkAll();
}
}
Expand Down Expand Up @@ -590,13 +593,18 @@ private static List<InstanSegModel> getRemoteModels() {
return List.copyOf(models);
}

private void configureTilePadding() {
tilePaddingChoiceBox.getItems().addAll(16, 32, 48, 64, 80, 96);
tilePaddingChoiceBox.setValue(InstanSegPreferences.tilePaddingProperty().getValue());
tilePaddingChoiceBox.valueProperty().addListener((v, o, n) -> InstanSegPreferences.tilePaddingProperty().set(n));
}


private void configureTileSizes() {
// The use of 32-bit signed ints for coordinates of the intermediate sparse matrix *might* be
// an issue for very large tile sizes - but I haven't seen any evidence of this.
// We definitely can't have very small tiles, because they must be greater than 2 x the padding.
tileSizeChoiceBox.getItems().addAll(256, 512, 1024, 2048);
tileSizeChoiceBox.getSelectionModel().select(Integer.valueOf(512));
tileSizeChoiceBox.setValue(InstanSegPreferences.tileSizeProperty().getValue());
tileSizeChoiceBox.valueProperty().addListener((v, o, n) -> InstanSegPreferences.tileSizeProperty().set(n));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ enum OnlinePermission {
"intanseg.tile.size",
512);

private static final IntegerProperty tilePaddingProperty = PathPrefs.createPersistentPreference(
"intanseg.tile.padding",
32);

private static final BooleanProperty makeMeasurementsProperty = PathPrefs.createPersistentPreference(
"intanseg.measurements",
true);
Expand Down Expand Up @@ -82,6 +86,10 @@ static IntegerProperty tileSizeProperty() {
return tileSizeProperty;
}

static IntegerProperty tilePaddingProperty() {
return tilePaddingProperty;
}

static BooleanProperty makeMeasurementsProperty() {
return makeMeasurementsProperty;
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class InstanSegTask extends Task<Void> {

@Override
protected Void call() {
int nThreads = InstanSegPreferences.numThreadsProperty().get();
var taskRunner = new TaskRunnerFX(
QuPathGUI.getInstance(),
InstanSegPreferences.numThreadsProperty().getValue());
nThreads);

var selectedObjects = imageData.getHierarchy().getSelectionModel().getSelectedObjects();
Optional<Path> path = model.getPath();
Expand All @@ -69,13 +70,16 @@ protected Void call() {
if (nChecked > 0 && nChecked < nOutputs) {
outputChannels = this.outputChannels.stream().mapToInt(Integer::intValue).toArray();
}
int tileSize = InstanSegPreferences.tileSizeProperty().get();
int tilePadding = InstanSegPreferences.tilePaddingProperty().get();

var instanSeg = InstanSeg.builder()
.model(model)
.device(device)
.inputChannels(channels.stream().map(InputChannelItem::getTransform).toList())
.outputChannels(outputChannels)
.tileDims(InstanSegPreferences.tileSizeProperty().get())
.tileDims(tileSize)
.interTilePadding(tilePadding)
.taskRunner(taskRunner)
.makeMeasurements(makeMeasurements)
.randomColors(randomColors)
Expand All @@ -88,6 +92,7 @@ protected Void call() {
.%s
.outputChannels(%s)
.tileDims(%d)
.interTilePadding(%d)
.nThreads(%d)
.makeMeasurements(%s)
.randomColors(%s)
Expand All @@ -100,8 +105,9 @@ protected Void call() {
outputChannels.length == 0 ? "" : Arrays.stream(outputChannels)
.mapToObj(Integer::toString)
.collect(Collectors.joining(", ")),
InstanSegPreferences.tileSizeProperty().get(),
InstanSegPreferences.numThreadsProperty().getValue(),
tileSize,
tilePadding,
nThreads,
makeMeasurements,
randomColors
).strip();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/qupath/ext/instanseg/ui/ModelListCell.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package qupath.ext.instanseg.ui;

import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ListCell;
import javafx.scene.control.Tooltip;
import org.controlsfx.glyphfont.FontAwesome;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void updateItem(InstanSegModel model, boolean empty) {

private Glyph createOnlineIcon() {
GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
return fontAwesome.create(FontAwesome.Glyph.DOWNLOAD);
return fontAwesome.create(FontAwesome.Glyph.CLOUD);
}

}
51 changes: 44 additions & 7 deletions src/main/resources/qupath/ext/instanseg/ui/instanseg_control.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
<Insets left="10" right="10" top="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.device" />
<Label styleClass="regular" text="%ui.options.device">
<tooltip>
<Tooltip text="%ui.options.device.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<ChoiceBox fx:id="deviceChoices" prefWidth="75.0">
<tooltip><Tooltip text="%ui.options.device.tooltip" /></tooltip>
Expand All @@ -149,7 +152,10 @@
<Insets left="10" right="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.threads" />
<Label styleClass="regular" text="%ui.options.threads">
<tooltip>
<Tooltip text="%ui.options.threads.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<Spinner fx:id="threadSpinner" prefWidth="75.0">
<tooltip>
Expand All @@ -167,7 +173,10 @@
<Insets left="10" right="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.tilesize" />
<Label styleClass="regular" text="%ui.options.tilesize">
<tooltip>
<Tooltip text="%ui.options.tilesize.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<ChoiceBox fx:id="tileSizeChoiceBox" prefWidth="75.0">
<tooltip>
Expand All @@ -176,13 +185,33 @@
</ChoiceBox>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" styleClass="standard-spacing">
<padding>
<Insets left="10" right="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.tileboundary">
<tooltip>
<Tooltip text="%ui.options.tileboundary.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<ChoiceBox fx:id="tilePaddingChoiceBox" prefWidth="75.0">
<tooltip>
<Tooltip text="%ui.options.tileboundary.tooltip" />
</tooltip>
</ChoiceBox>
</children>
</HBox>
<!-- Channel Selection-->
<HBox alignment="CENTER_RIGHT" styleClass="standard-spacing">
<padding>
<Insets left="10" right="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.input-channels" />
<Label styleClass="regular" text="%ui.options.input-channels">
<tooltip>
<Tooltip text="%ui.options.input-channels.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<CheckComboBox fx:id="comboInputChannels">
<tooltip>
Expand All @@ -196,7 +225,10 @@
<Insets left="10" right="10" />
</padding>
<children>
<Label styleClass="regular" text="%ui.options.output-channels" />
<Label styleClass="regular" text="%ui.options.output-channels">
<tooltip>
<Tooltip text="%ui.options.output-channels.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<CheckComboBox id="checkComboOutputs" fx:id="comboOutputChannels">
<tooltip>
Expand All @@ -209,7 +241,10 @@
<Insets left="10.0" right="10.0" />
</padding>
<children>
<Label text="%ui.options.makeMeasurements" />
<Label text="%ui.options.makeMeasurements">
<tooltip>
<Tooltip text="%ui.options.makeMeasurements.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<CheckBox fx:id="makeMeasurementsCheckBox" styleClass="regular">
<tooltip>
Expand All @@ -224,7 +259,9 @@
</padding>
<children>
<Label text="%ui.options.randomColors">
</Label>
<tooltip>
<Tooltip text="%ui.options.randomColors.tooltip" />
</tooltip></Label>
<Pane minWidth="5" HBox.hgrow="ALWAYS" />
<CheckBox fx:id="randomColorsCheckBox" styleClass="regular">
<tooltip>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/qupath/ext/instanseg/ui/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ ui.options.threads = Threads
ui.options.threads.tooltip = Define the preferred number of threads
ui.options.tilesize = Tile size
ui.options.tilesize.tooltip = Define the approximate tile size
ui.options.tileboundary = Tile padding
ui.options.tileboundary.tooltip = Define how much padding to add on tile boundaries.\nSmaller values can make processing faster, but may cause objects to be split or broken at tile boundaries.
ui.options.input-channels = Input channels
ui.options.input-channels.tooltip = Define the set of channels to be used in inference
ui.options.makeMeasurements = Make measurements
Expand Down