MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / image_mesh

Function image_mesh

eval_code/recons/models/moge/utils3d/torch/utils.py:121–153  ·  view source on GitHub ↗

Get a quad mesh regarding image pixel uv coordinates as vertices and image grid as faces. Args: width (int): image width height (int): image height mask (torch.Tensor, optional): binary mask of shape (height, width), dtype=bool. Defaults to None. Returns:

(height: int, width: int, mask: torch.Tensor = None, device: torch.device = None, dtype: torch.dtype = None)

Source from the content-addressed store, hash-verified

119
120
121def image_mesh(height: int, width: int, mask: torch.Tensor = None, device: torch.device = None, dtype: torch.dtype = None) -> Tuple[torch.Tensor, torch.Tensor]:
122 """
123 Get a quad mesh regarding image pixel uv coordinates as vertices and image grid as faces.
124
125 Args:
126 width (int): image width
127 height (int): image height
128 mask (torch.Tensor, optional): binary mask of shape (height, width), dtype=bool. Defaults to None.
129
130 Returns:
131 uv (torch.Tensor): uv corresponding to pixels as described in image_uv()
132 faces (torch.Tensor): quad faces connecting neighboring pixels
133 indices (torch.Tensor, optional): indices of vertices in the original mesh
134 """
135 if device is None and mask is not None:
136 device = mask.device
137 if mask is not None:
138 assert mask.shape[0] == height and mask.shape[1] == width
139 assert mask.dtype == torch.bool
140 uv = image_uv(height, width, device=device, dtype=dtype).reshape((-1, 2))
141 row_faces = torch.stack([
142 torch.arange(0, width - 1, dtype=torch.int32, device=device),
143 torch.arange(width, 2 * width - 1, dtype=torch.int32, device=device),
144 torch.arange(1 + width, 2 * width, dtype=torch.int32, device=device),
145 torch.arange(1, width, dtype=torch.int32, device=device)
146 ], dim=1)
147 faces = (torch.arange(0, (height - 1) * width, width, device=device, dtype=torch.int32)[:, None, None] + row_faces[None, :, :]).reshape((-1, 4))
148 if mask is not None:
149 quad_mask = (mask[:-1, :-1] & mask[1:, :-1] & mask[1:, 1:] & mask[:-1, 1:]).ravel()
150 faces = faces[quad_mask]
151 faces, uv, indices = mesh.remove_unreferenced_vertices(faces, uv, return_indices=True)
152 return uv, faces, indices
153 return uv, faces
154
155
156def depth_edge(depth: torch.Tensor, atol: float = None, rtol: float = None, kernel_size: int = 3, mask: torch.Tensor = None) -> torch.BoolTensor:

Callers 1

image_mesh_from_depthFunction · 0.70

Calls 1

image_uvFunction · 0.70

Tested by

no test coverage detected