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)
| 42 | |
| 43 | |
| 44 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected