diff --git a/src/main/java/ai/nets/samj/annotation/Mask.java b/src/main/java/ai/nets/samj/annotation/Mask.java index 00c0849..c8b1e25 100644 --- a/src/main/java/ai/nets/samj/annotation/Mask.java +++ b/src/main/java/ai/nets/samj/annotation/Mask.java @@ -75,7 +75,8 @@ public static RandomAccessibleInterval getMask(long width, lon byte[] arr = new byte[(int) (width * height)]; for (Mask mask : masks) { - for (int i = 0; i < mask.getRLEMask().length; i += 2) { + long[] rle = mask.getRLEMask(); + for (int i = 0; i < rle.length; i += 2) { int cropStartx = mask.crop.x; int cropStarty = mask.crop.y; int start = (int) (width * (cropStarty + i / 2) + cropStartx + mask.getRLEMask()[i]); diff --git a/src/main/java/ai/nets/samj/models/AbstractSamJ.java b/src/main/java/ai/nets/samj/models/AbstractSamJ.java index 8865c8e..86628cb 100644 --- a/src/main/java/ai/nets/samj/models/AbstractSamJ.java +++ b/src/main/java/ai/nets/samj/models/AbstractSamJ.java @@ -371,6 +371,8 @@ else if (task.outputs.get("contours_x") == null) throw new RuntimeException(); else if (task.outputs.get("contours_y") == null) throw new RuntimeException(); + else if (task.outputs.get("rles") == null) + throw new RuntimeException(); results = task.outputs; } catch (IOException | InterruptedException | RuntimeException e) { try { diff --git a/src/main/java/ai/nets/samj/models/PythonMethods.java b/src/main/java/ai/nets/samj/models/PythonMethods.java index e9b7e0b..d478f85 100644 --- a/src/main/java/ai/nets/samj/models/PythonMethods.java +++ b/src/main/java/ai/nets/samj/models/PythonMethods.java @@ -85,12 +85,14 @@ public class PythonMethods { + " y_contours = []" + System.lineSeparator() + " rles = []" + System.lineSeparator() + " sizes = []" + System.lineSeparator() + + " np.save('/home/carlos/git/test.npy', sam_result)" + System.lineSeparator() + " for obj in labels:" + System.lineSeparator() + " if obj.num_pixels >= at_least_of_this_size:" + System.lineSeparator() + " x_coords,y_coords = trace_contour(obj.image, obj.num_pixels, obj.bbox[1],obj.bbox[0])" + System.lineSeparator() + " rle = encode_rle(obj.image)" + System.lineSeparator() + + " bbox_w = obj.bbox[3] - obj.bbox[1]" + System.lineSeparator() + " for i in range(0, len(rle), 2):" + System.lineSeparator() - + " rle[i] += sam_result.shape[1] * (obj.bbox[0] + i) + obj.bbox[1]" + System.lineSeparator() + + " rle[i] = sam_result.shape[1] * (obj.bbox[0] - 1 + rle[i] // bbox_w) + obj.bbox[1] + rle[i] % bbox_w" + System.lineSeparator() + " rles.append(rle)" + System.lineSeparator() + " x_contours.append(x_coords)" + System.lineSeparator() + " y_contours.append(y_coords)" + System.lineSeparator()