Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get per vertex rgb color vector from textured Mesh #889

Closed
Pooya448 opened this issue Oct 19, 2021 · 15 comments
Closed

How to get per vertex rgb color vector from textured Mesh #889

Pooya448 opened this issue Oct 19, 2021 · 15 comments
Assignees
Labels
question Further information is requested

Comments

@Pooya448
Copy link

Hi everyone, I am relatively new to this field.

Using pytorch3d I have a textured mesh, which I added the texture information from png texture maps, and after rendering everything seems fine. But I want to extract per vertex rgb color value (rgb features) from this mesh.

When I use verts_uvs_padded() method it returns texture info corresponding to texture maps, But I want actual rgb values for every vertex: Tensor of shape (V, 3)

Is there a way to do this?
Thank you in advance

@bottler
Copy link
Contributor

bottler commented Oct 19, 2021

See issue #854 and my first comment. (Note that asking for a TexturesVertex is equivalent to a color per vertex).

@bottler bottler self-assigned this Oct 19, 2021
@bottler bottler added the question Further information is requested label Oct 19, 2021
@Pooya448
Copy link
Author

Pooya448 commented Oct 19, 2021

See issue #854 and my first comment. (Note that asking for a TexturesVertex is equivalent to a color per vertex).

Thank you for your quick reply.

Ok, but my ultimate goal is that convert the textured mesh to a colored point cloud, so I can render it with a point renderer.
I thought that taking vertices and per vertex colors from the mesh and then creating a pointcloud object would do the trick.
Is there a better way to do this?

Please take a look at my code which is based on your comment:

verts_colors_packed = torch.ones_like(mesh.verts_packed())
verts_colors_packed[mesh.faces_packed()] = mesh.textures.faces_verts_textures_packed()  # (*)

verts = mesh.verts_packed()
norms = mesh.verts_normals_packed()
rgb = verts_colors_packed

colored_ptc = Pointclouds(points=[verts], normals=[norms], features=[rgb])

Which I can render this pointcloud, but the render results are not good enough.

@bottler
Copy link
Contributor

bottler commented Oct 19, 2021

If you want more than just the vertices, then maybe you could use the sample_points_from_meshes operation to make a pointcloud from many points on the mesh?

https://github.com/facebookresearch/pytorch3d/blob/v0.6.0/pytorch3d/ops/sample_points_from_meshes.py

@Pooya448
Copy link
Author

Is this a built-in method which I can use?

@bottler
Copy link
Contributor

bottler commented Oct 19, 2021

yes. from pytorch3d.ops import sample_points_from_meshes

@Pooya448
Copy link
Author

Thank you very much for your quick and effective answers. I am closing this.

@Pooya448 Pooya448 reopened this Oct 30, 2021
@Pooya448
Copy link
Author

I am trying to sample points from a textured mesh, returning both normals and colors. the built in ops.sample_points_from_meshes samples from the points which are on the surface of the mesh.
I need to sample points from a normal distribution with a standard deviation of 5 cm from the mesh surface (i.e. sampling from points which are 5cm outer or inner the mesh surface)

is there a function in pytorch3d to do this? If not, is there a way?

Thanks.

@bottler
Copy link
Contributor

bottler commented Nov 1, 2021

This is a new question. You mean to exactly sample uniformly over the volume which is within 5cm of the mesh? I can only think of rejection sampling as a solution (i.e. sample from an axis-aligned cuboid surrounding 5cm around the mesh and select the points in the volume e.g. using pytorch3d.loss.point_mesh_face_distance).

@Pooya448
Copy link
Author

Pooya448 commented Nov 2, 2021

What about I sample points from the mesh surface and then add a gaussian noise to the points? can this achieve the goal?

@bottler
Copy link
Contributor

bottler commented Nov 2, 2021

I didn't read your previous comment precisely. You aren't looking for uniform over a volume. Still, it all depends on your exact goal, which isn't fully explained. E.g. the distribution can't both have a distance from the mesh which is "normal with a standard deviation of 5 cm" and be within 5cm outer or inner the mesh surface, because lots of a normal distribution is beyond 1 standard deviation.

If you sample from the surface and then add noise, then a small volume which is 1cm from two different flattish parts of the mesh will have about twice the probability as an equal-sized small volume which is 1cm from a single flattish part of the mesh. Is that good? Acceptable?

@Pooya448
Copy link
Author

Pooya448 commented Nov 2, 2021

I think yes.

Also, I'm trying to render normals of a mesh(or poitcloud) into an image. Can this be achieved by pytorch3d?

@bottler
Copy link
Contributor

bottler commented Nov 2, 2021

Do you mean you want to visualize the mesh along with normals as little arrows? If so, and you don't care about differentiability, that sounds useful but isn't in PyTorch3D. I think you can make this happen with plotly or matplotlib, and if you get this working it would be interesting.

@bottler
Copy link
Contributor

bottler commented Nov 2, 2021

In future please make sure you open a new issue for an unrelated question.

@nikhilaravi
Copy link
Contributor

@Pooya448 closing this issue as @bottler has answered all your questions in a lot of detail! Please reopen or create a new issue if you have any further questions.

@8bitnand
Copy link

Im having issues in displaying textured mesh in plotly graph,
can you share me your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants