Skip to content

Commit

Permalink
keep iterating on the improvement of big images, downsampling and rles
Browse files Browse the repository at this point in the history
for masks
  • Loading branch information
carlosuc3m committed Oct 30, 2024
1 parent 2a52e4b commit 13176e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/ai/nets/samj/annotation/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class Mask {

private final Polygon contour;

private final long[] rleEncoding;
// TODO private final long[] rleEncoding;
public long[] rleEncoding;

private Mask(Polygon contour, long[] rleEncoding) {
this.contour = contour;
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,19 @@ protected void recalculatePolys(List<Mask> masks, long[] encodeCoords) {
masks.stream().forEach(pp -> {
pp.getContour().xpoints = Arrays.stream(pp.getContour().xpoints).map(x -> x * scale + (int) encodeCoords[0]).toArray();
pp.getContour().ypoints = Arrays.stream(pp.getContour().ypoints).map(y -> y * scale + (int) encodeCoords[1]).toArray();
long[] upscaledRLE = new long[pp.getRLEMask().length * scale];
for (int i = 0; i < pp.getRLEMask().length; i += 2) {
pp.getRLEMask()[i] = encodeCoords[0] + (pp.getRLEMask()[i] * scale) % this.targetDims[0]
+ (((int) ((pp.getRLEMask()[i] * scale) / this.targetDims[0])) + encodeCoords[1]) * this.targetDims[0];
pp.getRLEMask()[i] *= scale;
int x = (int) (pp.getRLEMask()[i] % Math.ceil(this.targetDims[0] / (double) scale));
int y = (int) (pp.getRLEMask()[i] / Math.ceil(this.targetDims[0] / (double) scale));
int newX = x * scale;
int newY = y * scale;
long newLen = pp.getRLEMask()[i + 1] * scale;
for (int j = 0; j < scale; j ++) {
upscaledRLE[i * scale + j * 2] = newX + encodeCoords[0] + (newY + j) * this.img.dimensionsAsLongArray()[0];
upscaledRLE[i * scale + j * 2 + 1] = newLen;
}
}
pp.rleEncoding = upscaledRLE;
});
}

Expand Down

0 comments on commit 13176e1

Please sign in to comment.