Augmentations

class flat_bug.augmentations.FlatBugRandomPerspective(imgsz: int, *args, **kwargs)
affine_transform(img: ndarray, border: Tuple[int, int]) Tuple[ndarray, ndarray, float]

Center.

flat_bug.augmentations.apply_segments(segments: ndarray, M: ndarray) Tuple[ndarray, ndarray]

Apply affine to segments and generate new bboxes from segments.

Parameters:
  • segments (np.ndarray) – list of segments, [num_samples, 500, 2].

  • M (np.ndarray) – affine matrix.

Returns:

  • new_segments (np.ndarray): list of segments after affine, [num_samples, 500, 2].

  • new_bboxes (np.ndarray): bboxes after affine, [N, 4].

Return type:

out (Tuple[np.ndarray, np.ndarray])

flat_bug.augmentations.low_res_inpaint(img: ndarray, mask: ndarray, scale: int = 6) ndarray

Performs inpainting on a low-resolution version of the image, and then copies the upsampled inpainted image back into the original image.

flat_bug.augmentations.segment2box(segment: Tensor, width: int = 640, height: int = 640) ndarray

Convert 1 segment label to 1 box label, applying inside-image constraint, i.e. (xy1, xy2, …) to (xyxy).

Parameters:
  • segment (torch.Tensor) – the segment label

  • width (int, optional) – OBS: Unused. The width of the image. Defaults to 640.

  • height (int, optional) – OBS: Unused. The height of the image. Defaults to 640.

Returns:

the minimum and maximum x and y values of the segment.

Return type:

out (np.ndarray)

flat_bug.augmentations.telea_inpaint_polys(img: ndarray, polys: List[ndarray], exclude_polys: List[ndarray] | None = None, downscale_factor: int | float = 6, **kwargs) ndarray

Mutably inpaints the polygons in an image using the Fast Marching method by Alexandru Telea.

The inpainting algorithm is performed on a downsampled version of the image to speed up the process, and the inpainted results are then upsampled and pasted back into the original image.

Parameters:
  • img (np.ndarray) – The image to inpaint.

  • polys (List[np.ndarray]) – A list of polygons to inpaint.

  • exclude_polys (Optional[List[np.ndarray]], optional) – A list of polygons to exclude from inpainting. Defaults to None.

  • downscale_factor (Union[int, float], optional) – The factor by which to downscale the image before inpainting. Defaults to 6.

  • **kwargs – Additional keyword arguments to pass to cv2.drawContours.

Returns:

The inpainted image.

Return type:

out (np.ndarray)