-
Notifications
You must be signed in to change notification settings - Fork 4
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
Color / texture transfert #168
Comments
Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, it may be automatically transferred to https://github.com/pyvista/pyvista-support |
Is there any way you could upload your dataset here for us to take a look at it? |
Hi, thank you for your response! Here is a link to download a small dataset: https://drive.google.com/drive/folders/1ij6NdB1WuCnTXyK1SIolLSYIkfIMd6n2?usp=sharing This link contains 2 .off files, which are two shapes, that can be easily read using pyvista, a texture image that I want to apply to one shape and transfer it to another, and a file X_Y.mat which is a correspondance from X to Y. this file contains an array that has the shape: N x 1, where N is the number of vertices of X, and the value at row
The Thank you for your help, and hope this is what you asked for. |
So uh, I totally cannot follow what you mean by:
Can you clarify what you are trying to accomplish? In the meantime, we can load up all the data by: import scipy.io as sio
import pyvista as pv
import numpy as np
import imageio
# My build of libpng is broken... should use `pv.read_texture()`
texture = pv.numpy_to_texture(imageio.imread("small dataset/texture2.png"))
ds = sio.loadmat("small dataset/067_071.mat")
gt = (ds["matches_gt"] - 1).ravel()
est = (ds["matches_est"] - 1).ravel()
a = pv.read("small dataset/tr_reg_067.off")
b = pv.read("small dataset/tr_reg_071.off") From a quick inspection, the shapes of the What are we supposed to do with these data? Also, how did you texture map the meshes? |
Hi, Thank you for your response. We want to color the shape I hope that my explanation is clear. |
Hi all, I added to the link above 2 shapes, |
Ah okay, this is awesome! So how are you mapping the texture to the meshes? If you have a 1-to-1 relationship between the two meshes, then simply copy the texture coordinates across the two meshes and there's your texture transfer, right? |
Hi, Thank you for your response.
This way, I don't know how to transfer the coordinates! |
But, how did you generate the texture coordinates in the first place to create this figure:
will throw an error if you don't have texture coordinates. hopefully, this will add some context. In PyVista, a mesh can be plotted with scalars (numerical values associated with each node or cell in the mesh) or with textures (an image that is draped over the mesh via a texture coordinate mapping for all the nodes in the mesh). If your two meshes have a 1-to-1 correspondence, then they can share the same texture coordinates. The tricky part is creating texture coordinates for a complex mesh like yours to produce something like the image above. To do so, you need to map the coordinates of the texture image (0 to 1 in the U and V directions) to each node in the mesh so that you can properly drape your texture/image over the mesh. Here's an intuitive graphic I grabbed from a google search: Unfortunately, texture mapping isn't always a simple task. In PyVista, we have a This leads me to wonder how you are generating these meshes and if the tooling/software there is aware of what these texture coordinates should be but isn't saving them in the |
Hi @banesullivan Thank you for you response and explanation.
And the result is the following: |
Hm, okay. I have a feeling that texture mapping isn't exactly the best solution, but it looks decent enough! Try this: import pyvista as pv
import numpy as np
import imageio
a = pv.read("small dataset/surreal_0000.off")
b = pv.read("small dataset/surreal_0001.off")
texture = pv.numpy_to_texture(imageio.imread("small dataset/texture2.png"))
# Generate and transfer texture coordinates
a.texture_map_to_plane(inplace=True)
b.t_coords = a.t_coords
# Display
p = pv.Plotter(notebook=0, shape=(1,2))
p.add_mesh(a, texture=texture)
p.subplot(0,1)
p.add_mesh(b, texture=texture)
p.link_views()
p.show() |
Wow, cool! Thanks a lot @banesullivan !
with I have a question, is there a similar method to transfer color. For now, I can color gradually an image using the following:
|
Hi, Thank you for the awesome library!
Actually, I'm not reporting a bug, but I'm asking for help.
I'm working on a shape matching problem, where I have two meshes, and I want to assign to each vertex in the first mesh, a vertex in the second meshes. A way to visualize if the correspondances are correct is to transfert color (or texture) from one shape to the other. (see example below)


However, actually all this operation are done in matlab, and I want to perform this in python (in jupyter notebook using Panel).
I succeed to color the shape, or apply texture to it, but I can't see how to transfer this. (see below)


I had the idea to use the

scalars
property inadd_mesh
to transfer color, but when I use this, the color is not uniform on the source shape, which will be difficult to transfer (see below).Can you suggest a method to do this?
Thank you in advance.
The text was updated successfully, but these errors were encountered: