drtk.grid_scatter#
Scatter an image through a normalized sampling grid. |
|
Pure PyTorch reference implementation used by tests. |
- drtk.grid_scatter(input, grid, output_height, output_width, mode='bilinear', padding_mode='border', align_corners=None)[source]#
Scatter an image through a normalized sampling grid.
grid_scatteris the splatting counterpart oftorch.nn.functional.grid_sample(). Ingrid_sample, each output pixel reads from a source location in the input. Ingrid_scatter, each input pixel writes its value to a destination location described bygrid. The operation is useful for tasks such as projecting camera-view values into a UV texture atlas or accumulating visibility weights in texture space.The forward pass of
grid_scattercorresponds to the input-gradient accumulation performed bygrid_sample. The backward pass correspondingly samples gradients back from the output grid, while also producing gradients with respect togrid.- Parameters:
input – Source values with shape
(N, C, H, W).grid – Destination coordinates with shape
(N, H, W, 2). Coordinates use the same normalized[-1, 1]convention, padding modes, andalign_cornerssemantics as PyTorchgrid_sample.output_height – Height of the scattered output image.
output_width – Width of the scattered output image.
mode – Interpolation kernel. Supported values are
"bilinear"and"bicubic".padding_mode – Handling for samples outside the output image. Supported values are
"zeros","border", and"reflection".align_corners – Same meaning as in
grid_sample.Nonedefaults toFalse.
- Returns:
Tensor with shape
(N, C, output_height, output_width)containing the accumulated scattered values.
Note
Multiple input pixels can scatter to the same output pixel; their weighted contributions are accumulated. This operation currently requires the accelerator backend.
- drtk.grid_scatter_ref(input, grid, output_height, output_width, mode='bilinear', padding_mode='border', align_corners=None)[source]#
Pure PyTorch reference implementation used by tests.
This helper is intentionally not part of the documented public API. See
drtk.grid_scatter()for the supported implementation.