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

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

Closed
sugizo opened this issue May 16, 2024 · 2 comments
Closed

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

sugizo opened this issue May 16, 2024 · 2 comments
Labels

Comments

@sugizo
Copy link

sugizo commented May 16, 2024

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
Copy link
Owner

wolph commented May 28, 2024

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.

Copy link

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

@github-actions github-actions bot added the Stale label Jun 28, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants