cvcg_utils.uv package
cvcg_utils.uv.img2mesh module
- cvcg_utils.uv.img2mesh.make_masked_delaunay(mask)
mask: [H, W], bool
- cvcg_utils.uv.img2mesh.make_pixel_indices(H, W)
- cvcg_utils.uv.img2mesh.make_pixel_triangles(H, W)
generates triangles for an image of size (H, W):
pixel indices: [[0, 1, 2, …, W-1],
[W, W+1, …, 2W-1], … […, HW-1]]
- cvcg_utils.uv.img2mesh.make_pixel_uvs(H, W, homogeneous)
generates a pixel uv coord image
uv_imgof shape [H, W, 2], whereuv_img[i, j] = [i+0.5, j+0.5]is the center coordinates of pixel (i, j):[[0.5, 0.5], [1.5, 0.5], [2.5, 0.5], ..., [W-1.5, 0.5], [0.5, 1.5], [1.5, 1.5], [2.5, 1.5], ..., [W-1.5, 1.5], ... [0.5, H-1.5], [1.5, H-1.5], [2.5, H-1.5], ..., [W-1.5, H-1.5]]
If
homogeneousis True, the uv_img is padded with a constant value 1.- Parameters:
H (int) – height of the image
W (int) – width of the image
homogeneous (bool) – whether to make uv_img homogeneous
- Returns:
uv_img – uv coord image of shape [H, W, 2] or [H, W, 3] if
homogeneousis True- Return type:
np.ndarray
- cvcg_utils.uv.img2mesh.make_texture_uvs(H, W)
generates texture uv coord image
cvcg_utils.uv.posmap2normal module
- class cvcg_utils.uv.posmap2normal.Img2Grad(*args: Any, **kwargs: Any)
Bases:
Module- forward(img: torch.Tensor, mask: torch.Tensor) torch.Tensor
img: [b, c, h, w] mask: [b, h, w], bool
cvcg_utils.uv.test_rgb_xyz_to_mesh module
cvcg_utils.uv.test_rgb_xyz_to_mesh_delaunay module
cvcg_utils.uv.uv_module module
- cvcg_utils.uv.uv_module.convert_edge_uv_to_uv_mesh(edge_uv: torch.Tensor)
edge_uv: [N_faces, 3, 2] tensor storing edge uv coords, compatible with PLY formats.
- cvcg_utils.uv.uv_module.face_attr_to_uv(face_attrs, face_index_map, uv_mask)
face_attrs: [B, N, C] face_index_map: [H, W, 3] uv_mask: [H, W]
- cvcg_utils.uv.uv_module.get_bary_coords_2d(query_coords: torch.Tensor, target_tris: torch.Tensor)
Assuming we already know the triangles of each query point, i.e., dim 0 of query_coords and target_triangles are in correspondence
query_coords: [Nv, 2 (uv coords)] target_tris: [Nv, 3 (vertices of the tri), 2 (uv coords)]
- cvcg_utils.uv.uv_module.get_uv_assets(faces: torch.Tensor, uv_verts: torch.Tensor, uv_faces: torch.Tensor, uv_size: Tuple[int, int] | int, flip_v: bool = True) Tuple[torch.Tensor, torch.Tensor]
get the following assets for uv-based utils:
vert_index_map: [H, W, 3] face_index_map: [H, W] bary_coords_map: [H, W, 3] uv_mask: [H, W]
- cvcg_utils.uv.uv_module.get_uv_face_index_map(uv_verts: torch.Tensor, uv_faces: torch.Tensor, uv_size: Tuple[int, int] | int, flip_v: bool = True) torch.Tensor
uv_verts: [Nv_uv, 2], uv-space vertices uv_faces: [Nf, 3] triangles uv_size: (H, W) or just int
out: [H, W], with -1 denoting no triangles
- cvcg_utils.uv.uv_module.sample_texture_by_uv(uv: torch.Tensor, tex_img: torch.Tensor, padding_mode='border')
uv: [B, …, 2], (0, 0) is bottom left, (1, 1) is top right tex_img: [B, C, H, W]
out: [B, …, C]
- cvcg_utils.uv.uv_module.vert_attr_to_uv(vert_attrs, vert_index_map, bary_coords_map, uv_mask)
vert_attrs: [B, N, C] vert_index_map: [H, W, 3] bary_coords_map: [H, W, 3] uv_mask: [H, W]