Code: Select all
# normalize the flow field
# 3, W, H, D
opt_flow[0] /= (W-1)
opt_flow[1] /= (H-1)
opt_flow[2] /= (D-1)
# create the grid
# note that torch.meshgrid returns the directions as z, y, x
grid = torch.stack(torch.meshgrid([torch.linspace(-1, 1, i) for i in opt_flow.shape[1:]], indexing='ij'), 3).to(self.device)
# flip grid so that the directions are x, y, z
grid = torch.flip(grid, [3])
# D, H, W, 3
opt_flow = opt_flow.permute(1, 2, 3, 0)
# add the flow field to the grid to represent the new coordinates
# I have subtracted because initially I have thought that this would account for inverse optical field
grid -= opt_flow
# add batch dimension
grid = grid[None, ...]
applied = F.grid_sample(self._to_Tensor(img)[None, None, ...], grid, mode='bilinear', padding_mode='zeros', align_corners=True).squeeze(dim=(0, 1))
Vereinfachung eines 2D -Bildes, vermutlich mein FF verfügt über einen Verschiebungsvektor (3, 4) im Gitterindex (5, 6). In der Perspektive von Grid_Sample möchten wir, dass das IF -Raster (-3, -4) im Gitterindex (8, 10) speichert. Wenn Sie einfach negiert werden, wird (-3, -4) bei (5, 6) gespeichert, was den falschen Pixelwert während des Grid_Sample bringt. Es scheint jedoch nicht intuitiv, den BF auf das "vorherige" Bild anzuwenden. Aber gleichzeitig, da Grid_Sample "rückwärts" Warp ist, erscheint es auch intuitiv, das optische Feld "rückwärts" auf die Voraussetzung anzuwenden. j+y_displacement]. Aber dies wird eine nicht integrierbare Funktion sein. (Ist es in Ordnung, BF auf die Vorhilfe anzuwenden?)
[*] Wie kann ich eine integrierbare Vorwärts -Warp -Funktion erstellen?