@@ -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