Skip to content

Commit 9e4d33b

Browse files
committed
Simplify resize_mask_to_unpadded_box
1 parent 8cf5ef6 commit 9e4d33b

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

abraia/inference/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_mask(row, box, size):
5353
mask_x1, mask_y1 = round(x / size[0] * shape), round(y / size[1] * shape)
5454
mask_x2, mask_y2 = round((x + w) / size[0] * shape), round((y + h) / size[1] * shape)
5555
mask = mask[mask_y1:mask_y2, mask_x1:mask_x2]
56-
mask = cv2.resize(mask, (round(w), round(h)), cv2.INTER_AREA)
56+
mask = cv2.resize(mask, (round(w), round(h)), cv2.INTER_NEAREST)
5757
return mask
5858

5959

abraia/inference/ops.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,17 @@ def resize_mask_to_unpadded_box(mask_1d, box_on_input_image, box_on_padded_image
337337
Returns:
338338
np.ndarray: Resized 2D mask for the unpadded box size.
339339
"""
340-
# Step 1: Get the shape of the padded box
341340
x1_p, y1_p, x2_p, y2_p = box_on_padded_image
342-
h_p = y2_p - y1_p
343-
w_p = x2_p - x1_p
344-
# Step 2: Reshape the mask to original (padded) box shape
345-
try:
346-
mask_2d = mask_1d.reshape((h_p, w_p))
347-
except ValueError:
348-
closest_shape = find_shape_closest_to_target(mask_1d.size, h_p, w_p)
349-
if not closest_shape:
350-
return None
351-
h, w = closest_shape
352-
mask_2d = mask_1d.reshape((h, w))
353-
# Step 3: Get new shape after unpadding
341+
w_p, h_p = x2_p - x1_p, y2_p - y1_p
342+
mask_2d = mask_1d.reshape((h_p, w_p))
343+
# try:
344+
# mask_2d = mask_1d.reshape((h_p, w_p))
345+
# except ValueError:
346+
# closest_shape = find_shape_closest_to_target(mask_1d.size, h_p, w_p)
347+
# if not closest_shape:
348+
# return None
349+
# h, w = closest_shape
350+
# mask_2d = mask_1d.reshape((h, w))
354351
x1_u, y1_u, x2_u, y2_u = box_on_input_image
355-
h_u = y2_u - y1_u
356-
w_u = x2_u - x1_u
357-
# Step 4: Resize the mask to the unpadded box shape
358-
resized_mask = cv2.resize(mask_2d.astype(np.uint8), (w_u, h_u), interpolation=cv2.INTER_NEAREST)
352+
resized_mask = cv2.resize(mask_2d.astype(np.uint8), (x2_u - x1_u, y2_u - y1_u), interpolation=cv2.INTER_NEAREST)
359353
return resized_mask

0 commit comments

Comments
 (0)