@@ -52,17 +52,20 @@ Automatic tests can be performed by running `stl_tools/test/test_stl.py`.
52
52
Run the file ` examples.py ` to produce a few sample STL files from images included in ` examples/example_data ` .
53
53
54
54
The first example converts the commonly-used [ Lena test image] ( http://en.wikipedia.org/wiki/Lenna ) to an STL file
55
-
55
+ The "solid" keyword argument sets whether to create a solid geometry (with sides and a bottom) or not.
56
+ The algorithm used to generate the sides and bottom have not yet been optimized, so may double the file size
57
+ at the moment. We'll generate this example without a bottom.
56
58
``` python
57
59
from stl_tools import numpy2stl
58
60
59
61
from scipy.misc import lena, imresize
60
62
from scipy.ndimage import gaussian_filter
61
63
62
- A = imresize(lena(), (256 ,256 )) # load Lena image, shrink in half
63
- A = gaussian_filter(A, 1 ) # smoothing
64
64
65
- numpy2stl(A, " examples/Lena.stl" , scale = 0.1 )
65
+ A = imresize(lena(), (256 , 256 )) # load Lena image, shrink in half
66
+ A = gaussian_filter(A, 1 ) # smoothing
67
+
68
+ numpy2stl(A, " examples/Lena.stl" , scale = 0.1 , solid = False )
66
69
```
67
70
68
71
Source image vs. output geometry:
@@ -72,17 +75,18 @@ Source image vs. output geometry:
72
75
73
76
---
74
77
75
- The next three examples convert logos to STL, using color information to achieve appropriate 3D layering
78
+ The next two examples convert logos to STL, using color information to achieve appropriate 3D layering.
79
+ For this example, we'll generate a solid geometry (solid=True), for comparison to the first example.
76
80
77
81
Python code:
78
82
79
83
``` python
80
84
from pylab import imread
81
85
82
- A = 256 * imread(" examples/example_data/NASA.png" ) # 0 - 256 (8 bit) scale
83
- A = A[:,:, 2 ] + 1.0 * A[:,:, 0 ] # Compose RGBA channels to give depth
86
+ A = 256 * imread(" examples/example_data/NASA.png" )
87
+ A = A[:, :, 2 ] + 1.0 * A[:,:, 0 ] # Compose RGBA channels to give depth
84
88
A = gaussian_filter(A, 1 ) # smoothing
85
- numpy2stl(A, " examples/NASA.stl" , scale = 0.05 , mask_val = 5 .)
89
+ numpy2stl(A, " examples/NASA.stl" , scale = 0.05 , mask_val = 5 ., solid = True )
86
90
```
87
91
Equivalent command-line syntax:
88
92
``` bash
@@ -97,11 +101,10 @@ Equivalent command-line syntax:
97
101
Python code:
98
102
99
103
``` python
100
- A = 256 .* imread(" examples/example_data/openmdao.png" ) # 0 - 256 (8 bit) scale
101
- A = A[:,:,0 ] + 1 .* A[:,:,3 ] # Compose elements from RGBA channels to give depth
102
- A = gaussian_filter(A, 2 ) # smoothing
103
-
104
- numpy2stl(A, " examples/OpenMDAO-logo.stl" , scale = 0.05 , mask_val = 1 .)
104
+ A = 256 * imread(" examples/example_data/openmdao.png" )
105
+ A = A[:, :, 0 ] + 1 .* A[:,:, 3 ] # Compose some elements from RGBA to give depth
106
+ A = gaussian_filter(A, 2 ) # smoothing
107
+ numpy2stl(A, " examples/OpenMDAO-logo.stl" , scale = 0.05 , mask_val = 1 ., solid = False )
105
108
```
106
109
107
110
Equivalent command-line syntax:
0 commit comments