Skip to content

Commit

Permalink
Add option to make measurements (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan authored Aug 21, 2024
1 parent ac62573 commit 9ab48e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegController.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public class InstanSegController extends BorderPane {
private ToggleButton selectAllTMACoresButton;
@FXML
private CheckBox nucleiOnlyCheckBox;
@FXML
private CheckBox makeMeasurementsCheckBox;

private final ExecutorService pool = Executors.newSingleThreadExecutor(ThreadTools.createThreadFactory("instanseg", true));
private final QuPathGUI qupath;
Expand Down Expand Up @@ -440,7 +442,7 @@ protected Void call() {
InstanSegPreferences.numThreadsProperty().getValue());

var imageData = qupath.getImageData();
var selectedObjects = qupath.getImageData().getHierarchy().getSelectionModel().getSelectedObjects();
var selectedObjects = imageData.getHierarchy().getSelectionModel().getSelectedObjects();
var instanSeg = InstanSeg.builder()
.model(model)
.imageData(imageData)
Expand All @@ -452,10 +454,6 @@ protected Void call() {
.taskRunner(taskRunner)
.build();
instanSeg.detectObjects(selectedObjects);
for (PathObject po: selectedObjects) {
instanSeg.makeMeasurements(instanSeg.getImageData(), po.getChildObjects());
}
qupath.getImageData().getHierarchy().fireHierarchyChangedEvent(this);


String cmd = String.format("""
Expand All @@ -474,19 +472,27 @@ protected Void call() {
.nThreads(%d)
.build();
instanSeg.detectObjects(instanSegObjects);
""",
model.getPath(),
deviceChoices.getSelectionModel().getSelectedItem(),
nucleiOnlyCheckBox.isSelected() ? 1 : 2,
ChannelSelectItem.toConstructorString(channels),
InstanSegPreferences.tileSizeProperty().get(),
model.getPixelSizeX() / (double) server.getPixelCalibration().getAveragedPixelSize(),
InstanSegPreferences.numThreadsProperty().getValue()
);
if (makeMeasurementsCheckBox.isSelected()) {
cmd += """
for (PathObject po: instanSegObjects) {
instanSeg.makeMeasurements(instanSeg.getImageData(), po.getChildObjects());
}
""",
model.getPath(),
deviceChoices.getSelectionModel().getSelectedItem(),
nucleiOnlyCheckBox.isSelected() ? 1 : 2,
ChannelSelectItem.toConstructorString(channels),
InstanSegPreferences.tileSizeProperty().get(),
model.getPixelSizeX() / (double) server.getPixelCalibration().getAveragedPixelSize(),
InstanSegPreferences.numThreadsProperty().getValue()
);
qupath.getImageData().getHistoryWorkflow()
""";
for (PathObject po: selectedObjects) {
instanSeg.makeMeasurements(instanSeg.getImageData(), po.getChildObjects());
}
}
imageData.getHierarchy().fireHierarchyChangedEvent(this);
imageData.getHistoryWorkflow()
.addStep(
new DefaultScriptableWorkflowStep(resources.getString("workflow.title"), cmd)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
</CheckComboBox>
</children>
</HBox>
<HBox alignment="CENTER" styleClass="standard-spacing">
<children>
<CheckBox styleClass="regular" fx:id="makeMeasurementsCheckBox" text="%ui.options.makeMeasurements">
<tooltip>
<Tooltip text="%ui.options.makeMeasurements.tooltip" />
</tooltip>
</CheckBox>
</children>
</HBox>
<Separator prefWidth="200.0" />

<!-- Model Directory Selection-->
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 @@ -55,6 +55,8 @@ ui.options.tilesize = Tile Size:
ui.options.tilesize.tooltip = Define the approximate tile size
ui.options.channel = Channels:
ui.options.channel.tooltip = Define the set of channels to be used in inference
ui.options.makeMeasurements = Make measurements
ui.options.makeMeasurements.tooltip = Make shape and intensity measurements after detecting objects
ui.options.noChannelSelected = No channels selected!
ui.options.oneChannelSelected = 1 channel selected
ui.options.nChannelSelected = %d channels selected
Expand Down

0 comments on commit 9ab48e8

Please sign in to comment.