Possible bug in Pillow rasterization
See original GitHub issueRasterization using PIL doesn’t create a clean image when sectioning a mesh
geometry = trimesh.load_mesh(path)
slice = geometry.section(place_origin=[0, 0, 0.15], plane_normal = [0,0,1])
planar, _ = slice.to_planar(normal=[0, 0, 1])
im_origin = planar.bounds[0]
im = planar.rasterize(resolution, im_origin)
the file used is here : https://cdn.thingiverse.com/assets/7d/fc/6e/33/fe/3DBenchy.stl
I believe the issue is inside Pillow. I copied the rastization implementation and I just used scikit-image to draw ,instead of Pillow, and it fixed the issue.
from skimage import draw
def rasterize(
path: trimesh.path.Path2D, pitch: npt.NDArray, origin: npt.NDArray, resolution=None
) -> npt.NDArray:
pitch = np.asanyarray(pitch, dtype=np.float64)
origin = np.asanyarray(origin, dtype=np.float64)
# if resolution is None make it larger than path
if resolution is None:
span = np.vstack((path.bounds, origin)).ptp(axis=0)
resolution = np.ceil(span / pitch) + 2
im = np.zeros(resolution.astype(int)).astype(bool)
# get resolution as a (2,) int tuple
discrete = [((i - origin) / pitch).round().astype(np.int64) for i in path.discrete]
roots = path.root
enclosure = path.enclosure_directed
for root in roots:
outer = draw.polygon(discrete[root][:,0],discrete[root][:,1], shape = im.shape)
im[outer] = 1
for child in enclosure[root]:
hole = draw.polygon(discrete[child][:,0],discrete[child][:,1], shape = im.shape)
im[hole] = 0
return im
I can make a pull request if interested
Issue Analytics
- State:
- Created a year ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
5 Signs of Bed Bugs on Pillows You Shouldn't Ignore
Another telltale sign is if you see small black spots on your pillow, which is an indication of bed bug feces. If you...
Read more >Rasterization for vector graphics - Matplotlib
Rasterization converts vector graphics into a raster image (pixels). It can speed up rendering and produce smaller files for large data sets, ...
Read more >Four Effective Ways To Kill Bed Bugs In Pillows
Start with the mattress, checking underneath tufts and folds. Look for any blood stains, droppings, or smears on your bedding, blankets, pillows, and...
Read more >Can Bed Bugs Live and Lay Eggs in Pillows? | Mattress Advisor
Can bed bugs live in memory foam pillows? The answer is: very unlikely, but possible. Still, if bed bugs gain access and get...
Read more >Cross stitch calgary - Para Erboristeria Ruocco
The Stitch Bug 297 Mountain Rd When placing an order through the website, ... Large selection of yarn in all weights. interior by...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sounds good, I think I just need the
planar
slice exactly to reproduce, here’s what I was running:I created an issue on Pillow : https://github.com/python-pillow/Pillow/issues/6290