MCPcopy Create free account
hub / github.com/OpenTalker/StyleHEAT / warp_image

Function warp_image

utils/flow_util.py:44–59  ·  view source on GitHub ↗

r"""warp the input image according to the deformation Args: source_image (tensor): source images to be warpped deformation (tensor): deformations used to warp the images; value in range (-1, 1) Returns: output (tensor): the warpped images

(source_image, deformation)

Source from the content-addressed store, hash-verified

42
43
44def warp_image(source_image, deformation):
45 r"""warp the input image according to the deformation
46
47 Args:
48 source_image (tensor): source images to be warpped
49 deformation (tensor): deformations used to warp the images; value in range (-1, 1)
50 Returns:
51 output (tensor): the warpped images
52 """
53 _, h_old, w_old, _ = deformation.shape
54 _, _, h, w = source_image.shape
55 if h_old != h or w_old != w:
56 deformation = deformation.permute(0, 3, 1, 2)
57 deformation = torch.nn.functional.interpolate(deformation, size=(h, w), mode='bilinear')
58 deformation = deformation.permute(0, 2, 3, 1)
59 return torch.nn.functional.grid_sample(source_image, deformation)
60
61
62

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected