Skip to content

Commit f8ebb38

Browse files
Fix patch/bbox generation for nuclick (#1157)
Signed-off-by: SACHIDANAND ALLE <[email protected]> Signed-off-by: SACHIDANAND ALLE <[email protected]>
1 parent 9a0bf41 commit f8ebb38

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

plugins/qupath/src/main/java/qupath/lib/extension/monailabel/InteractorTool.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,23 @@ public void mousePressed(MouseEvent e) {
7373
}
7474
}
7575

76-
int w = Math.max((int) roi.getBoundsWidth() + 20, selectedPatchSize);
77-
int h = Math.max((int) roi.getBoundsHeight() + 20, selectedPatchSize);
78-
int x = Math.max(0, (int) roi.getCentroidX() - w / 2);
79-
int y = Math.max(0, (int) roi.getCentroidY() - h / 2);
76+
int min_x = Integer.MAX_VALUE;
77+
int min_y = Integer.MAX_VALUE;
78+
int max_x = 0;
79+
int max_y = 0;
80+
for (var p : roi.getAllPoints()) {
81+
int x = (int) p.getX();
82+
int y = (int) p.getY();
83+
min_x = Math.min(x, min_x);
84+
min_y = Math.min(y, min_y);
85+
max_x = Math.max(x, max_x);
86+
max_y = Math.max(y, max_y);
87+
}
88+
89+
int w = Math.max(max_x - min_x + 20, selectedPatchSize);
90+
int h = Math.max(max_y - min_y + 20, selectedPatchSize);
91+
int x = Math.max(0, min_x + (max_x - min_x) / 2 - w / 2);
92+
int y = Math.max(0, min_y + (max_y - min_y) / 2 - h / 2);
8093
int[] bbox = { x, y, w, h };
8194

8295
RunInference.runInference(selectedModel, info, bbox, selectedPatchSize, viewer.getImageData());

plugins/qupath/src/main/java/qupath/lib/extension/monailabel/commands/RunInference.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public static void runInference(String model, ResponseInfo info, int[] bbox, int
197197
if ((im.endsWith(".png") || im.endsWith(".jpg") || im.endsWith(".jpeg"))
198198
&& new File(imageFile).exists()) {
199199
logger.info("Simple Image.. will directly upload the same");
200+
offsetX = offsetY = 0;
200201
} else {
201202
if (bbox[2] == 0 && bbox[3] == 0) {
202203
Dialogs.showErrorMessage("MONAILabel",

0 commit comments

Comments
 (0)