Convert box to int16 mask image, which has the same size with the input image. Args: bg_label: background labels for the output mask image, make sure it is smaller than any foreground(fg) labels. ellipse_mask: bool. - If True, it assumes the object shape is clo
| 398 | |
| 399 | |
| 400 | class BoxToMask(Transform): |
| 401 | """ |
| 402 | Convert box to int16 mask image, which has the same size with the input image. |
| 403 | |
| 404 | Args: |
| 405 | bg_label: background labels for the output mask image, make sure it is smaller than any foreground(fg) labels. |
| 406 | ellipse_mask: bool. |
| 407 | |
| 408 | - If True, it assumes the object shape is close to ellipse or ellipsoid. |
| 409 | - If False, it assumes the object shape is close to rectangle or cube and well occupies the bounding box. |
| 410 | - If the users are going to apply random rotation as data augmentation, we suggest setting ellipse_mask=True |
| 411 | See also Kalra et al. "Towards Rotation Invariance in Object Detection", ICCV 2021. |
| 412 | """ |
| 413 | |
| 414 | backend = [TransformBackends.NUMPY] |
| 415 | |
| 416 | def __init__(self, bg_label: int = -1, ellipse_mask: bool = False) -> None: |
| 417 | self.bg_label = bg_label |
| 418 | self.ellipse_mask = ellipse_mask |
| 419 | |
| 420 | def __call__( # type: ignore |
| 421 | self, boxes: NdarrayOrTensor, labels: NdarrayOrTensor, spatial_size: Sequence[int] | int |
| 422 | ) -> NdarrayOrTensor: |
| 423 | """ |
| 424 | Args: |
| 425 | boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``. |
| 426 | labels: classification foreground(fg) labels corresponding to `boxes`, dtype should be int, sized (N,). |
| 427 | spatial_size: image spatial size. |
| 428 | |
| 429 | Return: |
| 430 | - int16 array, sized (num_box, H, W). Each channel represents a box. |
| 431 | The foreground region in channel c has intensity of labels[c]. |
| 432 | The background intensity is bg_label. |
| 433 | """ |
| 434 | return convert_box_to_mask(boxes, labels, spatial_size, self.bg_label, self.ellipse_mask) |
| 435 | |
| 436 | |
| 437 | class MaskToBox(Transform): |
no outgoing calls
no test coverage detected
searching dependent graphs…