Label Utils

hasty.label_utils.rle_encoding(x: array)

Encode binary mask to RLE

Parameters

x (np.array) – numpy array of shape (height, width), 1 - mask, 0 - background

Returns run length as list

hasty.label_utils.rle_decode(mask_rle: List[int], shape: Tuple[int])

Decodes mask from RLE format to binary mask. Returns numpy array, 1 - mask, 0 - background

Parameters
  • mask_rle (list) – run-length as string formated (start length)

  • shape (tuple) – (width, height) of array to return

hasty.label_utils.yolo2hasty(yolo_bbox: List[float], image_width: int, image_height: int)

Converts normalized YOLO bbox format (Xn_center, Yn_center, Wn, Hn) to Hasty format (x_min, y_min, x_max, y_max)

Parameters
  • yolo_bbox (list of floats) – Normalized coordinates [X_center, Y_center, W, H] example [0.3, 0.4, 0.1, 0.25]

  • image_width (int) – Image width

  • image_height (int) – Image height

hasty.label_utils.polygon2box(polygon: List[List[int]])

Converts polygon to bounding box [x_min, y_min, x_max, y_max]

Parameters

polygon – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]