Skip to content

Commit

Permalink
add possibility of crops of the image
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 25, 2024
1 parent f8c6a82 commit 0673f1a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/ai/nets/samj/annotation/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ai.nets.samj.annotation;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.List;

Expand All @@ -40,13 +41,16 @@ public class Mask {

private final long[] rleEncoding;

private Mask(Polygon contour, long[] rleEncoding) {
private final Rectangle crop;

private Mask(Polygon contour, long[] rleEncoding, Rectangle crop) {
this.contour = contour;
this.rleEncoding = rleEncoding;
this.crop = crop;
}

public static Mask build(Polygon contour, long[] rleEncoding) {
return new Mask(contour, rleEncoding);
public static Mask build(Polygon contour, long[] rleEncoding, Rectangle crop) {
return new Mask(contour, rleEncoding, crop);
}

public Polygon getContour() {
Expand All @@ -72,7 +76,8 @@ public static RandomAccessibleInterval<UnsignedByteType> getMask(long width, lon

for (Mask mask : masks) {
for (int i = 0; i < mask.getRLEMask().length; i += 2) {
int start = (int) mask.getRLEMask()[i];
int cropStart = mask.crop.x;
int start = cropStart + (int) mask.getRLEMask()[i];
int len = (int) mask.getRLEMask()[i+ 1];
Arrays.fill(arr, start, start + len, (byte) 1);
}
Expand Down

0 comments on commit 0673f1a

Please sign in to comment.