Apply the transform on an axis-aligned box. By default will transform the corner points and use their minimum/maximum to create a new axis-aligned box. Note that this default may change the size of your box, e.g. after rotations. Args: box (ndarr
(self, box: np.ndarray)
| 104 | return self.apply_image(segmentation) |
| 105 | |
| 106 | def apply_box(self, box: np.ndarray) -> np.ndarray: |
| 107 | """ |
| 108 | Apply the transform on an axis-aligned box. By default will transform |
| 109 | the corner points and use their minimum/maximum to create a new |
| 110 | axis-aligned box. Note that this default may change the size of your |
| 111 | box, e.g. after rotations. |
| 112 | |
| 113 | Args: |
| 114 | box (ndarray): Nx4 floating point array of XYXY format in absolute |
| 115 | coordinates. |
| 116 | Returns: |
| 117 | ndarray: box after apply the transformation. |
| 118 | |
| 119 | Note: |
| 120 | The coordinates are not pixel indices. Coordinates inside an image of |
| 121 | shape (H, W) are in range [0, W] or [0, H]. |
| 122 | |
| 123 | This function does not clip boxes to force them inside the image. |
| 124 | It is up to the application that uses the boxes to decide. |
| 125 | """ |
| 126 | # Indexes of converting (x0, y0, x1, y1) box into 4 coordinates of |
| 127 | # ([x0, y0], [x1, y0], [x0, y1], [x1, y1]). |
| 128 | idxs = np.array([(0, 1), (2, 1), (0, 3), (2, 3)]).flatten() |
| 129 | coords = np.asarray(box).reshape(-1, 4)[:, idxs].reshape(-1, 2) |
| 130 | coords = self.apply_coords(coords).reshape((-1, 4, 2)) |
| 131 | minxy = coords.min(axis=1) |
| 132 | maxxy = coords.max(axis=1) |
| 133 | trans_boxes = np.concatenate((minxy, maxxy), axis=1) |
| 134 | return trans_boxes |
| 135 | |
| 136 | def apply_polygons(self, polygons: list) -> list: |
| 137 | """ |
no test coverage detected