Skip to content

Commit

Permalink
keep improving things
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 28, 2024
1 parent a0ee50b commit f9f6243
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 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 @@ -75,7 +75,8 @@ public static RandomAccessibleInterval<UnsignedByteType> 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]);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ai/nets/samj/models/PythonMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f9f6243

Please sign in to comment.