Compute a boolean mask of the valid pixels resulting from an homography applied to an image of a given shape. Pixels that are False correspond to bordering artifacts. A margin can be discarded using erosion. Arguments: input_shape: Tensor of rank 2 representing the image sh
(image_shape, inv_homography, device='cpu', erosion_radius=0)
| 303 | return warped_img |
| 304 | |
| 305 | def compute_valid_mask(image_shape, inv_homography, device='cpu', erosion_radius=0): |
| 306 | """ |
| 307 | Compute a boolean mask of the valid pixels resulting from an homography applied to |
| 308 | an image of a given shape. Pixels that are False correspond to bordering artifacts. |
| 309 | A margin can be discarded using erosion. |
| 310 | |
| 311 | Arguments: |
| 312 | input_shape: Tensor of rank 2 representing the image shape, i.e. `[H, W]`. |
| 313 | homography: Tensor of shape (B, 8) or (8,), where B is the batch size. |
| 314 | `erosion_radius: radius of the margin to be discarded. |
| 315 | |
| 316 | Returns: a Tensor of type `tf.int32` and shape (H, W). |
| 317 | """ |
| 318 | |
| 319 | if inv_homography.dim() == 2: |
| 320 | inv_homography = inv_homography.view(-1, 3, 3) |
| 321 | batch_size = inv_homography.shape[0] |
| 322 | mask = torch.ones(batch_size, 1, image_shape[0], image_shape[1]).to(device) |
| 323 | mask = inv_warp_image_batch(mask, inv_homography, device=device, mode='nearest') |
| 324 | mask = mask.view(batch_size, image_shape[0], image_shape[1]) |
| 325 | mask = mask.cpu().numpy() |
| 326 | if erosion_radius > 0: |
| 327 | kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (erosion_radius*2,)*2) |
| 328 | for i in range(batch_size): |
| 329 | mask[i, :, :] = cv2.erode(mask[i, :, :], kernel, iterations=1) |
| 330 | |
| 331 | return torch.tensor(mask).to(device) |
| 332 | |
| 333 | def Kalman1D(observations,damping=1): |
| 334 | # To return the smoothed time series data |
nothing calls this directly
no test coverage detected