MCPcopy Create free account
hub / github.com/dcharatan/flowmap / sample_image_grid

Function sample_image_grid

flowmap/model/projection.py:93–113  ·  view source on GitHub ↗

Get normalized (range 0 to 1) coordinates and integer indices for an image.

(
    shape: tuple[int, ...],
    device: torch.device = torch.device("cpu"),
)

Source from the content-addressed store, hash-verified

91
92
93def sample_image_grid(
94 shape: tuple[int, ...],
95 device: torch.device = torch.device("cpu"),
96) -> tuple[
97 Float[Tensor, "*shape dim"], # float coordinates (xy indexing)
98 Int64[Tensor, "*shape dim"], # integer indices (ij indexing)
99]:
100 """Get normalized (range 0 to 1) coordinates and integer indices for an image."""
101
102 # Each entry is a pixel-wise integer coordinate. In the 2D case, each entry is a
103 # (row, col) coordinate.
104 indices = [torch.arange(length, device=device) for length in shape]
105 stacked_indices = torch.stack(torch.meshgrid(*indices, indexing="ij"), dim=-1)
106
107 # Each entry is a floating-point coordinate in the range (0, 1). In the 2D case,
108 # each entry is an (x, y) coordinate.
109 coordinates = [(idx + 0.5) / length for idx, length in zip(indices, shape)]
110 coordinates = reversed(coordinates)
111 coordinates = torch.stack(torch.meshgrid(*coordinates, indexing="xy"), dim=-1)
112
113 return coordinates, stacked_indices
114
115
116def reproject_points(

Callers 10

get_frustumsFunction · 0.90
load_birdsFunction · 0.90
visualizeMethod · 0.85
align_surfacesFunction · 0.85
forwardMethod · 0.85
forwardMethod · 0.85
forwardMethod · 0.85
export_to_colmapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected