STL to binary mask conversion
Show older comments
I have an STL file and I would like to make a binary mask from it in MATLAB, that would be defined similarly to this:
stl_mask = zeros(size(stl_file));
stl_mask(stl_indices) = 1
I have searched around and there is a stlread function that lets me visualize the STL file in MATLAB, but I am a bit lost on how to work around it. This is the STL file that I'm using. For the moment, I have just this small code to visualize the STL file:
clearvars;
filename = 'example.STL';
[v, f, n, c, stltitle] = stlread(filename);
figure;
patch('Faces',f,'Vertices',v,'FaceVertexCData',c);
grid on; view(45, 25); daspect([1 1 1]); camlight(-30,-30);
figure;
plot3(v(:,1),v(:,2),v(:,3),'.');
I have also checked the stl_slice_and_plot function from https://es.mathworks.com/matlabcentral/fileexchange/62113-slice_stl_create_path-triangles-slice_height . It gives a nice plot of the contours, but again, I would need some help on how to convert the contour plot into (x y z) coordinates to generate a mask:
%this script shows how everything works together
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Sunil Bhandari
%3/17/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear vars; close all;
triangles = read_binary_stl_file('example.STL');
original = triangles;
triangles = rotate_stl(triangles,'y',90);
slice_height = .1;
tic;[movelist, z_slices] = slice_stl_create_path(triangles, slice_height);toc;
%'plotting'
plot_slices(movelist,z_slices, 0)
Thank you
Accepted Answer
More Answers (0)
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!