MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / get_gt_correspondence_mask

Function get_gt_correspondence_mask

core/utils/utils.py:316–342  ·  view source on GitHub ↗

Computes the mask of valid flows (that do not match to a pixel outside of the image).

(flow)

Source from the content-addressed store, hash-verified

314 return map.astype(np.float32)
315
316def get_gt_correspondence_mask(flow):
317 """Computes the mask of valid flows (that do not match to a pixel outside of the image). """
318 mapping = convert_flow_to_mapping(flow, output_channel_first=True)
319 print(mapping.shape)
320 if isinstance(mapping, np.ndarray):
321 if len(mapping.shape) == 4:
322 # shape is B,C,H,W
323 b, _, h, w = mapping.shape
324 mask_x = np.logical_and(mapping[:, 0] > 0, mapping[:, 0] < w)
325 mask_y = np.logical_and(mapping[:, 1] > 0, mapping[:, 1] < h)
326 mask = np.logical_and(mask_x, mask_y)
327 else:
328 _, h, w = mapping.shape
329 mask_x = np.logical_and(mapping[0] > 0, mapping[0] < w)
330 mask_y = np.logical_and(mapping[1] > 0, mapping[1] < h)
331 mask = np.logical_and(mask_x, mask_y)
332 mask = mask.astype(np.bool) if float(torch.__version__[:3]) >= 1.1 else mask.astype(np.uint8)
333 else:
334 if len(mapping.shape) == 4:
335 # shape is B,C,H,W
336 b, _, h, w = mapping.shape
337 mask = mapping[:, 0].ge(0) & mapping[:, 0].le(w) & mapping[:, 1].ge(0) & mapping[:, 1].le(h)
338 else:
339 _, h, w = mapping.shape
340 mask = mapping[0].ge(0) & mapping[0].le(w) & mapping[1].ge(0) & mapping[1].le(h)
341 mask = mask.bool() if float(torch.__version__[:3]) >= 1.1 else mask.byte()
342 return mask
343
344def image_flow_warp(image, flow, padding_mode='zeros'):
345 ''&#x27;

Callers

nothing calls this directly

Calls 1

convert_flow_to_mappingFunction · 0.85

Tested by

no test coverage detected