MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / compute_valid_mask

Function compute_valid_mask

script/utils/utils.py:305–331  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

303 return warped_img
304
305def 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
333def Kalman1D(observations,damping=1):
334 # To return the smoothed time series data

Callers

nothing calls this directly

Calls 1

inv_warp_image_batchFunction · 0.85

Tested by

no test coverage detected