Skip to content

Commit

Permalink
set a minimum side size for encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Apr 23, 2024
1 parent e131eb8 commit b5e6dab
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public abstract class AbstractSamJ implements AutoCloseable {

public static long MAX_ENCODED_AREA_RS = 1024;

public static long MIN_ENCODED_AREA_SIDE = 128;

public static long MAX_ENCODED_SIDE = MAX_ENCODED_AREA_RS * 3;

protected static long ENCODE_MARGIN = 20;
Expand Down Expand Up @@ -637,6 +639,14 @@ public Rectangle getCurrentlyEncodedArea() {
int xMargin = (int) (targetDims[0] * 0.1);
int yMargin = (int) (targetDims[1] * 0.1);
Rectangle alreadyEncoded;
alreadyEncoded = new Rectangle((int) encodeCoords[0], (int) encodeCoords[1],
(int) targetDims[0], (int) targetDims[1]);
return alreadyEncoded;
/**
* TODO
* TODO
* TODO
* TODO
if (encodeCoords[0] != 0 || encodeCoords[1] != 0 || targetDims[1] != this.img.dimensionsAsLongArray()[1]
|| targetDims[0] != this.img.dimensionsAsLongArray()[0]) {
alreadyEncoded = new Rectangle((int) encodeCoords[0] + xMargin / 2, (int) encodeCoords[1] + yMargin / 2,
Expand All @@ -646,6 +656,7 @@ public Rectangle getCurrentlyEncodedArea() {
(int) targetDims[0], (int) targetDims[1]);
}
return alreadyEncoded;
*/
}

/**
Expand All @@ -670,7 +681,7 @@ private void evaluateReencodingNeeded(List<int[]> pointsList, List<int[]> points
&& alreadyEncoded.width + alreadyEncoded.x >= rect.width + rect.x
&& alreadyEncoded.height + alreadyEncoded.y >= rect.height + rect.y
&& alreadyEncoded.width * 0.9 < rect.width && alreadyEncoded.height * 0.9 < rect.height
&& notInRect.size() == 0) {
&& notInRect.size() == 0 && alreadyEncoded.contains(neededArea)) {
return;
} else if (notInRect.size() != 0) {
this.encodeCoords = new long[] {rect.x, rect.y};
Expand Down Expand Up @@ -746,8 +757,8 @@ private Rectangle getApproximateAreaNeeded(List<int[]> pointsList, List<int[]> p
Rectangle rect = new Rectangle();
rect.x = minX;
rect.y = minY;
rect.width = maxX - minX;
rect.height = maxY - minY;
rect.width = (int) Math.max(maxX - minX, MIN_ENCODED_AREA_SIDE);
rect.height = (int) Math.max(maxY - minY, MIN_ENCODED_AREA_SIDE);
return rect;
}

Expand Down Expand Up @@ -831,6 +842,8 @@ protected long[] calculateEncodingNewCoords(int[] boundingBox, long[] imageSize)
}
long[] newSize = new long[] {biggerSize, smallerSize};
if (ySize > xSize) newSize = new long[] {smallerSize, biggerSize};
newSize[0] = Math.max(MIN_ENCODED_AREA_SIDE, newSize[0]);
newSize[1] = Math.max(MIN_ENCODED_AREA_SIDE, newSize[1]);
long[] posWrtBbox = new long[4];
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));
Expand Down

0 comments on commit b5e6dab

Please sign in to comment.