How can I analyze stl files and then redraw them in matlab? I need to write some code
Afficher commentaires plus anciens
Hello
I need help and guidance.
This is the goal. I need to write code in matlab to analyze some stl pictures and then redraw it in matlab. I could also use solidworks too, but I don't have a lot of experience in solidworks. Anything helps Thanks
Réponses (2)
KSSV
le 15 Juin 2018
0 votes
YOu can read .stl files using this function: https://in.mathworks.com/matlabcentral/fileexchange/22409-stl-file-reader?focused=5193625&tab=function
1 commentaire
JoshT_student
le 15 Juin 2018
For context:
I have no idea where this was going, but here's an implausible interpretation of "STL from pseudobinary image":
unzip stuff.zip % for the forum
% an antialiased RGB image
inpict = imread('SEM.png');
% get rid of extraneous channels
inpict = im2gray(inpict);
% binarize it and get the blob boundaries
mk = imbinarize(inpict);
[Vc,~,nblobs] = bwboundaries(mk);
% show boundary curves atop the mask
imshow(mk); hold on
for k = 1:nblobs
plot(Vc{k}(:,2),Vc{k}(:,1),'linewidth',2)
end
% flip a bunch of stuff
for k = 1:nblobs
% the source is an image, so we probably want to invert Y
Vc{k}(:,1) = size(inpict,1) - Vc{k}(:,1) + 1;
% flipping Y means we need to flip the boundary direction
% also need to remove duplicate vertex on closure
% B is [y x]; we need that flipped too
Vc{k} = Vc{k}(end-1:-1:1,[2 1]);
end
% consolidate the vertex list
V = cell2mat(Vc);
% construct the edge lists in the same direction
% the vertex lists in Vc don't need to be the same length
sz = cellfun(@(x) size(x,1),Vc); % length of each vertex list
szc = [0; cumsum(sz)];
E = zeros(0,2);
for k = 1:numel(Vc)
v = 1+szc(k):szc(k+1);
thisE = [v; circshift(v,-1)].';
E = [E; thisE];
end
% TRIANGULATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% do a constrained triangulation to generate the triangles
T = delaunayTriangulation(V(:,1:2),E);
F = T.ConnectivityList(isInterior(T),:);
V = T.Points;
% or better yet, use mesh2D (FEX #25555)
%[V,~,F,~] = refine2(V,E);
% clean up leftover points
[F V] = pruneunusedverts(F,V);
% display it using patch()
figure
patch('faces',F,'vertices',V, ...
'facecolor','w','edgecolor','k');
axis equal; grid on
xlabel('X'); ylabel('Y')
% EXTRUSION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% extrude the part into 3D
[F V] = extrude(F,V,50); % pick a thickness
% write to file
stlwrite(triangulation(F,V),'testfile.stl')
% display it using patch()
figure
patch('faces',F,'vertices',V, ...
'facecolor','w','edgecolor','none');
view(3); camlight; view(10,33)
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
For other interpretations, see also:
Generate a lofted relief from a 2D depthmap image
Similar lofting or dithering for a lithophane
Yeah, but how would i do the lofting in 2012???
Extruding a logical image
Catégories
En savoir plus sur Vector Volume Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


