Convert int16 mask image to box, which has the same size with the input image. Pairs with :py:class:`monai.apps.detection.transforms.array.BoxToMask`. Please make sure the same ``min_fg_label`` is used when using the two transforms in pairs. Args: bg_label: background label
| 435 | |
| 436 | |
| 437 | class MaskToBox(Transform): |
| 438 | """ |
| 439 | Convert int16 mask image to box, which has the same size with the input image. |
| 440 | Pairs with :py:class:`monai.apps.detection.transforms.array.BoxToMask`. |
| 441 | Please make sure the same ``min_fg_label`` is used when using the two transforms in pairs. |
| 442 | |
| 443 | Args: |
| 444 | bg_label: background labels for the output mask image, make sure it is smaller than any foreground(fg) labels. |
| 445 | box_dtype: output dtype for boxes |
| 446 | label_dtype: output dtype for labels |
| 447 | """ |
| 448 | |
| 449 | backend = [TransformBackends.NUMPY] |
| 450 | |
| 451 | def __init__( |
| 452 | self, |
| 453 | bg_label: int = -1, |
| 454 | box_dtype: DtypeLike | torch.dtype = torch.float32, |
| 455 | label_dtype: DtypeLike | torch.dtype = torch.long, |
| 456 | ) -> None: |
| 457 | self.bg_label = bg_label |
| 458 | self.box_dtype = box_dtype |
| 459 | self.label_dtype = label_dtype |
| 460 | |
| 461 | def __call__(self, boxes_mask: NdarrayOrTensor) -> tuple[NdarrayOrTensor, NdarrayOrTensor]: |
| 462 | """ |
| 463 | Args: |
| 464 | boxes_mask: int16 array, sized (num_box, H, W). Each channel represents a box. |
| 465 | The foreground region in channel c has intensity of labels[c]. |
| 466 | The background intensity is bg_label. |
| 467 | |
| 468 | Return: |
| 469 | - bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``. |
| 470 | - classification foreground(fg) labels, dtype should be int, sized (N,). |
| 471 | """ |
| 472 | return convert_mask_to_box(boxes_mask, self.bg_label, self.box_dtype, self.label_dtype) |
| 473 | |
| 474 | |
| 475 | class SpatialCropBox(SpatialCrop): |
no outgoing calls
no test coverage detected
searching dependent graphs…