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

Function inv_warp_image_batch

script/utils/utils.py:270–303  ·  view source on GitHub ↗

Inverse warp images in batch :param img: batch of images tensor [batch_size, 1, H, W] :param mat_homo_inv: batch of homography matrices tensor [batch_size, 3, 3] :param device: GPU device or CPU :return: batch of warped images

(img, mat_homo_inv, device='cpu', mode='bilinear')

Source from the content-addressed store, hash-verified

268 return warped_points[0,:,:] if no_batches else warped_points
269
270def inv_warp_image_batch(img, mat_homo_inv, device='cpu', mode='bilinear'):
271 '''
272 Inverse warp images in batch
273
274 :param img:
275 batch of images
276 tensor [batch_size, 1, H, W]
277 :param mat_homo_inv:
278 batch of homography matrices
279 tensor [batch_size, 3, 3]
280 :param device:
281 GPU device or CPU
282 :return:
283 batch of warped images
284 tensor [batch_size, 1, H, W]
285 '''
286 # compute inverse warped points
287 if len(img.shape) == 2 or len(img.shape) == 3:
288 img = img.view(1,1,img.shape[0], img.shape[1])
289 if len(mat_homo_inv.shape) == 2:
290 mat_homo_inv = mat_homo_inv.view(1,3,3)
291
292 Batch, channel, H, W = img.shape
293 coor_cells = torch.stack(torch.meshgrid(torch.linspace(-1, 1, W), torch.linspace(-1, 1, H), indexing='ij'), dim=2)
294 coor_cells = coor_cells.transpose(0, 1)
295 coor_cells = coor_cells.to(device)
296 coor_cells = coor_cells.contiguous()
297
298 src_pixel_coords = warp_points(coor_cells.view([-1, 2]), mat_homo_inv, device)
299 src_pixel_coords = src_pixel_coords.view([Batch, H, W, 2])
300 src_pixel_coords = src_pixel_coords.float()
301
302 warped_img = F.grid_sample(img, src_pixel_coords, mode=mode, align_corners=True)
303 return warped_img
304
305def compute_valid_mask(image_shape, inv_homography, device='cpu', erosion_radius=0):
306 """

Callers 1

compute_valid_maskFunction · 0.85

Calls 1

warp_pointsFunction · 0.85

Tested by

no test coverage detected