image_to_mesh.py 730 B

1234567891011121314151617181920212223242526
  1. # Transform a image into a mesh
  2. from vedo import Image, dataurl, show
  3. import numpy as np
  4. img = Image(dataurl+"images/dog.jpg").smooth(5)
  5. msh = img.tomesh() # make a quad-mesh out of it
  6. # build a scalar array with intensities
  7. rgb = msh.pointdata["RGBA"]
  8. intensity = np.sum(rgb, axis=1)
  9. intensityz = np.zeros_like(rgb)
  10. intensityz[:,2] = intensity / 10
  11. # set the new vertex points
  12. msh.points += intensityz
  13. # more cosmetics
  14. msh.triangulate().smooth()
  15. msh.lighting("default").cmap("bone", "RGBA")
  16. msht = img.clone().threshold(100)
  17. show([[img, "A normal jpg image.."],
  18. [msh, "..becomes a polygonal Mesh"],
  19. [msht, "Thresholding also generates a Mesh"]
  20. ], N=3, axes=1, zoom=1.1, elevation=-20, bg='black').close()