wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

can't make image array into *.stl #221

Open sugizo opened 1 month ago

sugizo commented 1 month ago

env google colab

steps

!curl -LC - https://static.wikia.nocookie.net/batman/images/6/68/Batman_Logo.png -o batman.png
pip install -U numpy-stl

code

from stl import mesh
import numpy as np
from PIL import Image
img = Image.open("batman.png")
numpy_array = np.array(img)
your_mesh = mesh.Mesh(numpy_array, remove_empty_areas=False)
your_mesh.save('tes.stl', mode=stl.Mode.ASCII)  

result

IndexError                                Traceback (most recent call last)
[<ipython-input-26-30c87a446cab>](https://localhost:8080/#) in <cell line: 6>()
      4 img = Image.open("batman.png")
      5 numpy_array = np.array(img)
----> 6 your_mesh = mesh.Mesh(numpy_array, remove_empty_areas=False)
      7 your_mesh.save('tes.stl', mode=stl.Mode.ASCII)

3 frames
[/usr/local/lib/python3.10/dist-packages/stl/base.py](https://localhost:8080/#) in vectors(self)
    213     @property
    214     def vectors(self):
--> 215         return self.data['vectors']
    216 
    217     @vectors.setter

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

expected result can make image array into *.stl

best regards

wolph commented 1 month ago

I'm not entirely sure what you are trying to do here, but an image contains pixel data which you could convert to a point cloud perhaps, but it's a long way from the triangles in a 3D model. If you had vector data such as an svg file you could turn it into a flat 3D object perhaps, but this makes no sense to me.

github-actions[bot] commented 4 days ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days