Skip to content

Commit 9d40bec

Browse files
authored
Merge pull request #21 from ksugar/dev
0.5.0 -> 0.6.0
2 parents 20bcdbd + 7654321 commit 9d40bec

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ This is a part of the following paper. Please [cite](#citation) it when you use
1212

1313
## Install
1414

15-
Drag and drop [the extension file](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.5.0/qupath-extension-sam-0.5.0.jar) to [QuPath](https://qupath.github.io) and restart it.
15+
Drag and drop [the extension file](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.6.0/qupath-extension-sam-0.6.0.jar) to [QuPath](https://qupath.github.io) and restart it.
1616

1717
Since QuPath v0.5.0, you can install the extension from the extension manager dialog by specifying `Owner` and `Repository` as shown below.
1818

1919
<img src="https://github.com/ksugar/qupath-extension-sam/releases/download/assets/qupath-extension-manager.png" width="768">
2020

21-
If you are using QuPath v0.4.x, you need to install [the extension file for QuPath v0.4.x](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.4.1/qupath-extension-sam-0.4.1.jar).
21+
If you are using QuPath v0.4.x, you need to install [the extension file for QuPath v0.4.x](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.4.1/qupath-extension-sam-0.4.1.jar), which is now deprecated.
2222

2323
Please note that you need to set up the server following the instructions in the link below.
2424

@@ -30,10 +30,10 @@ To update the `qupath-extension-sam`, follow the following instructions.
3030

3131
1. Open extensions directory from `Extensions` > `Installed extensions` > `Open extensions directory`
3232
![](https://github.com/ksugar/qupath-extension-sam/releases/download/assets/open-extensions-directory.png)
33-
2. Replace `qupath-extension-sam-x.y.z.jar` with [the latest version of the extension file](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.5.0/qupath-extension-sam-0.5.0.jar). If you are using QuPath v0.4.x, you need to install [the extension file for QuPath v0.4.x](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.4.1/qupath-extension-sam-0.4.1.jar).
33+
2. Replace `qupath-extension-sam-x.y.z.jar` with [the latest version of the extension file](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.6.0/qupath-extension-sam-0.6.0.jar). If you are using QuPath v0.4.x, you need to install [the extension file for QuPath v0.4.x](https://github.com/ksugar/qupath-extension-sam/releases/download/v0.4.1/qupath-extension-sam-0.4.1.jar), which is now deprecated.
3434
3. Restart QuPath application.
3535

36-
Please note that you need to also update the [samapi](https://github.com/ksugar/samapi/tree/v0.4.0) server.
36+
Please note that you need to also update the [samapi](https://github.com/ksugar/samapi/tree/v0.5.0) server.
3737
To keep updated with the latest samapi server, follow the instructions [here](https://github.com/ksugar/samapi#update).
3838

3939
## Usage
@@ -69,7 +69,7 @@ To keep updated with the latest samapi server, follow the instructions [here](ht
6969
| key | value |
7070
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7171
| Server | URL of the server. |
72-
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, or `vit_t (mobile)`. |
72+
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, `vit_t (mobile)`, `sam2_l (large)`, `sam2_bp (base plus)`, `sam2_s (small)`, or `sam2_t (tiny)`. |
7373
| SAM weights | The SAM weights to use. The options are automatically fetched from the server. |
7474
| Output type | If `Single Mask` is selected, the model will return single masks per prompt. If `Multi-mask` is selected, the model will return three masks per prompt. `Multi-mask (all)` keeps all three masks. One of the three masks is kept if the option `Multi-mask (largest)`, `Multi-mask (smallest)`, or `Multi-mask (best quality)` is selected. |
7575
| Display names | Display the annotation names in the viewer. (this is a global preference) |
@@ -90,7 +90,7 @@ To keep updated with the latest samapi server, follow the instructions [here](ht
9090
| key | value |
9191
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9292
| Server | URL of the server. |
93-
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, or `vit_t (mobile)`. |
93+
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, `vit_t (mobile)`, `sam2_l (large)`, `sam2_bp (base plus)`, `sam2_s (small)`, or `sam2_t (tiny)`. |
9494
| SAM weights | The SAM weights to use. The options are automatically fetched from the server. |
9595
| Assign random colors | If checked and no path class is set in `Auto set` setting, assign random colors to new (unclassified) objects created by SAM. |
9696
| Assign names | If checked, assign names to identify new objects as created by SAM, including quality scores. |
@@ -120,11 +120,11 @@ The weights file is downloaded from the URL and registered on the server. After
120120

121121
#### Parameters
122122

123-
| key | value |
124-
| -------- | ----------------------------------------------------------------------------- |
125-
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, or `vit_t (mobile)`. |
126-
| Name | The SAM weights name to register. It needs to be unique in the same SAM type. |
127-
| URL | The URL to the SAM weights file. |
123+
| key | value |
124+
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
125+
| SAM type | One of `vit_h (huge)`, `vit_l (large)`, `vit_b (base)`, `vit_t (mobile)`, `sam2_l (large)`, `sam2_bp (base plus)`, `sam2_s (small)`, or `sam2_t (tiny)`. |
126+
| Name | The SAM weights name to register. It needs to be unique in the same SAM type. |
127+
| URL | The URL to the SAM weights file. |
128128

129129
#### SAM weights catalog
130130

@@ -173,6 +173,10 @@ If you select a class in `Auto set` in the Annotations tab, it is used for a new
173173

174174
## Updates
175175

176+
### v0.6.0
177+
- Support [SAM2](https://ai.meta.com/sam2/) models. The SAM2 models are available from the [samapi](https://github.com/ksugar/samapi) server `v0.5.0` and above.
178+
- Use the current view for the encoder input in the rectangle mode.
179+
176180
### v0.5.0
177181
- QuPath v0.5 support by [@Rylern](https://github.com/Rylern) and [@ksugar](https://github.com/ksugar) in [ksugar/samapi#12](https://github.com/ksugar/qupath-extension-sam/pull/12)
178182

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins {
1313
ext.moduleName = 'org.elephant.sam.qupath'
1414

1515
// TODO: Define the extension version & provide a short description
16-
version = "0.5.0"
16+
version = "0.6.0"
1717
description = 'QuPath extension for Segment Anything Model (SAM)'
1818

1919
// TODO: Specify the QuPath version, compatible with the extension.

src/main/java/org/elephant/sam/SAMExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GitHubRepo getRepository() {
6161

6262
@Override
6363
public Version getQuPathVersion() {
64-
return Version.parse("0.5.0");
64+
return Version.parse("0.6.0");
6565
}
6666

6767
}

src/main/java/org/elephant/sam/entities/SAMType.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public enum SAMType {
77

8-
VIT_H, VIT_L, VIT_B, VIT_T;
8+
VIT_H, VIT_L, VIT_B, VIT_T, SAM2_L, SAM2_BP, SAM2_S, SAM2_T;
99

1010
/**
1111
* Model name as used in the SAM code.
@@ -22,10 +22,17 @@ public String modelName() {
2222
return "vit_b";
2323
case VIT_T:
2424
return "vit_t";
25+
case SAM2_L:
26+
return "sam2_l";
27+
case SAM2_BP:
28+
return "sam2_bp";
29+
case SAM2_S:
30+
return "sam2_s";
31+
case SAM2_T:
32+
return "sam2_t";
2533
}
2634
throw new IllegalArgumentException("Unknown SAM model");
2735
}
28-
2936

3037
@Override
3138
public String toString() {
@@ -39,6 +46,14 @@ public String toString() {
3946
return "vit_b (base)";
4047
case VIT_T:
4148
return "vit_t (mobile)";
49+
case SAM2_L:
50+
return "sam2_l (large)";
51+
case SAM2_BP:
52+
return "sam2_bp (base plus)";
53+
case SAM2_S:
54+
return "sam2_s (small)";
55+
case SAM2_T:
56+
return "sam2_t (tiny)";
4257
}
4358
throw new IllegalArgumentException("Unknown SAM model");
4459
}

src/main/java/org/elephant/sam/tasks/SAMDetectionTask.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,19 @@ private List<PathObject> detectObjects(PathObject foregroundObject, List<? exten
147147
RegionRequest regionRequest;
148148
BufferedImage img;
149149
double downsample = this.viewerRegion.getDownsample();
150+
// Updated in version 0.6.0
151+
// For both rectangular and point prompts (including line vertices), use the current viewer region
152+
regionRequest = this.viewerRegion;
153+
img = renderedServer.readRegion(regionRequest);
150154
if (roi instanceof RectangleROI) {
151155
// For rectangular prompts, add some extra context from nearby
152156
RegionRequest roiRegion = RegionRequest.createInstance(renderedServer.getPath(), downsample, roi);
153-
154-
regionRequest = roiRegion;
155-
double minPadding = 128 / downsample; // We need to handle tiny input prompts (including single pixels)
156-
if (padScale > 0.0)
157-
regionRequest = regionRequest.pad2D(
158-
(int) Math.max(minPadding, Math.round(roiRegion.getWidth() * padScale)),
159-
(int) Math.max(minPadding, Math.round(roiRegion.getHeight() * padScale)));
160-
regionRequest = regionRequest.intersect2D(0, 0, renderedServer.getWidth(), renderedServer.getHeight());
161-
img = renderedServer.readRegion(regionRequest);
162-
163157
promptBuilder = promptBuilder.bbox(
164158
(int) ((roiRegion.getMinX() - regionRequest.getMinX()) / downsample),
165159
(int) ((roiRegion.getMinY() - regionRequest.getMinY()) / downsample),
166160
(int) Math.round((roiRegion.getMaxX() - regionRequest.getMinX()) / downsample),
167161
(int) Math.round((roiRegion.getMaxY() - regionRequest.getMinY()) / downsample));
168162
} else {
169-
// For point prompts (including line vertices), use the current viewer region
170-
regionRequest = this.viewerRegion;
171-
img = renderedServer.readRegion(regionRequest);
172163
promptBuilder = promptBuilder.addToForeground(
173164
Utils.getCoordinates(roi, regionRequest, img.getWidth(), img.getHeight()));
174165
}

0 commit comments

Comments
 (0)