Skip to content

Commit

Permalink
keep improving
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Apr 19, 2024
1 parent 11f26e9 commit 9215584
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/ai/nets/samj/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ protected long[] calculateEncodingNewCoords(int[] boundingBox, long[] imageSize)
long[] newSize = new long[] {biggerSize, smallerSize};
if (ySize > xSize) newSize = new long[] {smallerSize, biggerSize};
long[] posWrtBbox = new long[4];
posWrtBbox[0] = (long) Math.ceil((boundingBox[0] + xSize / 2) - newSize[0] / 2);
posWrtBbox[1] = (long) Math.ceil((boundingBox[1] + ySize / 2) - newSize[1] / 2);
posWrtBbox[2] = (long) Math.floor((boundingBox[2] + xSize / 2) + newSize[0] / 2);
posWrtBbox[3] = (long) Math.floor((boundingBox[3] + ySize / 2) + newSize[1] / 2);
posWrtBbox[0] = (long) Math.max(0, Math.ceil((boundingBox[0] + xSize / 2) - newSize[0] / 2));
posWrtBbox[1] = (long) Math.max(0, Math.ceil((boundingBox[1] + ySize / 2) - newSize[1] / 2));
posWrtBbox[2] = (long) Math.min(imageSize[1], Math.floor((boundingBox[2] + xSize / 2) + newSize[0] / 2));
posWrtBbox[3] = (long) Math.min(imageSize[0], Math.floor((boundingBox[3] + ySize / 2) + newSize[1] / 2));
return posWrtBbox;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/ai/nets/samj/EfficientSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,15 @@ public List<Polygon> processBox(int[] boundingBox)
*/
public List<Polygon> processBox(int[] boundingBox, boolean returnAll)
throws IOException, RuntimeException, InterruptedException {
int[] adaptedBoundingBox = new int[] {(int) (boundingBox[0] - encodeCoords[0]), (int) (boundingBox[1] - encodeCoords[1]),
(int) (boundingBox[2] - encodeCoords[0]), (int) (boundingBox[3] - encodeCoords[1])};;
if (needsMoreResolution(boundingBox)) {
this.encodeCoords = calculateEncodingNewCoords(boundingBox, this.img.dimensionsAsLongArray());
reencodeCrop();
} else if (!isAreaEncoded(boundingBox)) {
this.encodeCoords = calculateEncodingNewCoords(boundingBox, this.img.dimensionsAsLongArray());
adaptedBoundingBox = new int[] {(int) (boundingBox[0] - encodeCoords[0]), (int) (boundingBox[1] - encodeCoords[1]),
(int) (boundingBox[2] - encodeCoords[0]), (int) (boundingBox[3] - encodeCoords[1])};
reencodeCrop();
}
int[] adaptedBoundingBox = new int[] {(int) (boundingBox[0] - encodeCoords[0]), (int) (boundingBox[1] - encodeCoords[1]),
(int) (boundingBox[2] - encodeCoords[0]), (int) (boundingBox[3] - encodeCoords[1])};;
this.script = "";
processBoxWithSAM(returnAll);
HashMap<String, Object> inputs = new HashMap<String, Object>();
Expand Down

0 comments on commit 9215584

Please sign in to comment.