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

Displaying images as 3D objects #20

Open
FrankNiemeyer opened this issue Oct 20, 2023 · 2 comments
Open

Displaying images as 3D objects #20

FrankNiemeyer opened this issue Oct 20, 2023 · 2 comments

Comments

@FrankNiemeyer
Copy link

FrankNiemeyer commented Oct 20, 2023

I need to display images (2D) as 3D objects. My idea was to use the images as textures for simple rectangles consisting of two triangles each.

I tried to use plain vtkPolyData for that as suggested .

I used the following code to test the basic idea:

import skimage as ski
import numpy as np
import vtkplotlib as vpl

image = ski.io.imread("image_AP.png") # uint8 gray scale image
rgb_image = ski.color.gray2rgb(image)
texmap = vpl.colors.TextureMap(rgb_image, interpolate=True)

image_PolyData = vpl.PolyData()
# four vertices forming a square
image_PolyData.points = np.array([
    [0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [1.0, 1.0, 0.0],
    [1.0, 0.0, 0.0]], dtype=float)
# rectangle consisting of two triangles
image_PolyData.polygons = np.array([
    [0, 1, 3],
    [1, 2, 3]])
image_PolyData.texture_map = texmap
# UV coordinates for the four vertices
image_PolyData.point_colors = np.array([
    [0.0, 0.0],
    [0.0, 1.0],
    [1.0, 1.0],
    [1.0, 0.0]])

image_PolyData.quick_show()

This works, in principle, however it seems that pixels in between the vertices are simply interpolated between the vertices instead of using the actual texture information.

Is this by design or a bug? Is it possible to actually map the texture onto the polydata faces?

@bwoodsend
Copy link
Owner

This works, in principle, however it seems that pixels in between the vertices are simply interpolated between the vertices instead of using the actual texture information.

You're right, it's a naive implementation. I don't know what I was thinking when I published that API. I knew this would come back to bite me one day.

I don't have a quick fix for this I'm afraid. I'd need to go digging though vtkTexture and write a Python wrapper for it.

@FrankNiemeyer
Copy link
Author

Thanks. Good to know it's not because I was doing something wrong. ;)

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

No branches or pull requests

2 participants