Skip to content

Commit

Permalink
create one label per object
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 28, 2024
1 parent 3bab7b8 commit a6db425
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/ai/nets/samj/annotation/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import java.util.Arrays;
import java.util.List;

import io.bioimage.modelrunner.tensor.Utils;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedShortType;

/**
* Class that contains the information required to create the contour and mask about the object annotated in an image
Expand Down Expand Up @@ -67,17 +66,19 @@ public long[] getRLEMask() {
* all the masks of the objects image
* @return the whole mask with all the objects
*/
public static RandomAccessibleInterval<UnsignedByteType> getMask(long width, long height, List<Mask> masks) {
byte[] arr = new byte[(int) (width * height)];

public static RandomAccessibleInterval<UnsignedShortType> getMask(long width, long height, List<Mask> masks) {
short[] arr = new short[(int) (width * height)];
int n = 1;
for (Mask mask : masks) {
long[] rle = mask.getRLEMask();
for (int i = 0; i < rle.length; i += 2) {
int start = (int) mask.getRLEMask()[i];
int len = (int) mask.getRLEMask()[i+ 1];
Arrays.fill(arr, start, start + len, (byte) 1);
Arrays.fill(arr, start, start + len, (short) n);
}
n ++;
}
return Utils.transpose(ArrayImgs.unsignedBytes(arr, new long[] {height, width}));
//return Utils.transpose(ArrayImgs.unsignedBytes(arr, new long[] {height, width}));
return (ArrayImgs.unsignedShorts(arr, new long[] {width, height}));
}
}

0 comments on commit a6db425

Please sign in to comment.