mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-21 06:40:35 +08:00
align_corners and padding for TexturesUV
Summary: Allow, and make default, align_corners=True for texture maps. Allow changing the padding_mode and set the default to be "border" which produces more logical results. Some new documentation. The previous behavior corresponds to padding_mode="zeros" and align_corners=False. Reviewed By: gkioxari Differential Revision: D23268775 fbshipit-source-id: 58d6229baa591baa69705bcf97471c80ba3651de
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d0cec028c7
commit
e25ccab3d9
@@ -443,19 +443,26 @@ class TestTexturesUV(TestCaseMixin, unittest.TestCase):
|
||||
dists=pix_to_face,
|
||||
)
|
||||
|
||||
tex = TexturesUV(maps=tex_map, faces_uvs=[face_uvs], verts_uvs=[vert_uvs])
|
||||
meshes = Meshes(verts=[dummy_verts], faces=[face_uvs], textures=tex)
|
||||
mesh_textures = meshes.textures
|
||||
texels = mesh_textures.sample_textures(fragments)
|
||||
for align_corners in [True, False]:
|
||||
tex = TexturesUV(
|
||||
maps=tex_map,
|
||||
faces_uvs=[face_uvs],
|
||||
verts_uvs=[vert_uvs],
|
||||
align_corners=align_corners,
|
||||
)
|
||||
meshes = Meshes(verts=[dummy_verts], faces=[face_uvs], textures=tex)
|
||||
mesh_textures = meshes.textures
|
||||
texels = mesh_textures.sample_textures(fragments)
|
||||
|
||||
# Expected output
|
||||
pixel_uvs = interpolated_uvs * 2.0 - 1.0
|
||||
pixel_uvs = pixel_uvs.view(2, 1, 1, 2)
|
||||
tex_map = torch.flip(tex_map, [1])
|
||||
tex_map = tex_map.permute(0, 3, 1, 2)
|
||||
tex_map = torch.cat([tex_map, tex_map], dim=0)
|
||||
expected_out = F.grid_sample(tex_map, pixel_uvs, align_corners=False)
|
||||
self.assertTrue(torch.allclose(texels.squeeze(), expected_out.squeeze()))
|
||||
# Expected output
|
||||
pixel_uvs = interpolated_uvs * 2.0 - 1.0
|
||||
pixel_uvs = pixel_uvs.view(2, 1, 1, 2)
|
||||
tex_map_ = torch.flip(tex_map, [1]).permute(0, 3, 1, 2)
|
||||
tex_map_ = torch.cat([tex_map_, tex_map_], dim=0)
|
||||
expected_out = F.grid_sample(
|
||||
tex_map_, pixel_uvs, align_corners=align_corners, padding_mode="border"
|
||||
)
|
||||
self.assertTrue(torch.allclose(texels.squeeze(), expected_out.squeeze()))
|
||||
|
||||
def test_textures_uv_init_fail(self):
|
||||
# Maps has wrong shape
|
||||
|
||||
Reference in New Issue
Block a user