mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-19 22:00:35 +08:00
images for debugging TexturesUV
Summary: New methods to directly plot a TexturesUV map with its used points, using PIL and matplotlib. Reviewed By: gkioxari Differential Revision: D23782968 fbshipit-source-id: 692970857b5be13a35a3175dc82ac03963a73555
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b149bbfb3c
commit
aa4cc0adbc
BIN
tests/data/texturesuv_debug.png
Normal file
BIN
tests/data/texturesuv_debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 KiB |
@@ -2,10 +2,13 @@
|
||||
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
from common_testing import TestCaseMixin
|
||||
from PIL import Image
|
||||
from pytorch3d.renderer.mesh.rasterizer import Fragments
|
||||
from pytorch3d.renderer.mesh.textures import (
|
||||
TexturesAtlas,
|
||||
@@ -15,9 +18,14 @@ from pytorch3d.renderer.mesh.textures import (
|
||||
pack_rectangles,
|
||||
)
|
||||
from pytorch3d.structures import Meshes, list_to_packed, packed_to_list
|
||||
from pytorch3d.vis import texturesuv_image_PIL
|
||||
from test_meshes import TestMeshes
|
||||
|
||||
|
||||
DEBUG = False
|
||||
DATA_DIR = Path(__file__).resolve().parent / "data"
|
||||
|
||||
|
||||
def tryindex(self, index, tex, meshes, source):
|
||||
tex2 = tex[index]
|
||||
meshes2 = meshes[index]
|
||||
@@ -471,6 +479,10 @@ class TestTexturesAtlas(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
|
||||
class TestTexturesUV(TestCaseMixin, unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
torch.manual_seed(42)
|
||||
|
||||
def test_sample_textures_uv(self):
|
||||
barycentric_coords = torch.tensor(
|
||||
[[0.5, 0.3, 0.2], [0.3, 0.6, 0.1]], dtype=torch.float32
|
||||
@@ -821,6 +833,22 @@ class TestTexturesUV(TestCaseMixin, unittest.TestCase):
|
||||
tryindex(self, index, tex, meshes, source)
|
||||
tryindex(self, [2, 4], tex, meshes, source)
|
||||
|
||||
def test_png_debug(self):
|
||||
maps = torch.rand(size=(1, 256, 128, 3)) * torch.tensor([0.8, 1, 0.8])
|
||||
verts_uvs = torch.rand(size=(1, 20, 2))
|
||||
faces_uvs = torch.zeros(size=(1, 0, 3), dtype=torch.int64)
|
||||
tex = TexturesUV(maps=maps, faces_uvs=faces_uvs, verts_uvs=verts_uvs)
|
||||
|
||||
image = texturesuv_image_PIL(tex, radius=3)
|
||||
image_out = np.array(image)
|
||||
if DEBUG:
|
||||
image.save(DATA_DIR / "texturesuv_debug_.png")
|
||||
|
||||
with Image.open(DATA_DIR / "texturesuv_debug.png") as image_ref_file:
|
||||
image_ref = np.array(image_ref_file)
|
||||
|
||||
self.assertClose(image_out, image_ref)
|
||||
|
||||
|
||||
class TestRectanglePacking(TestCaseMixin, unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user