How to do mesh segmentation in Matlab
21 次查看(过去 30 天)
显示 更早的评论
Hello,
my goal is to approximate/represent CAD-Meshes with primitive bodies, eg. cuboids, spheres, cylinders etc. in Matlab. I consider the segmentation of the models into coherent regions an important step towards that goal.
The following figures show a trisurf'd example model, out of which I would like to extract several cylinders and probably some cuboids.
I am aware that there are several scientific papers on mesh segmentation and also some on primitive extraction. However, I have never before programmed an entire algorithm from a scientific paper.
What I am asking is: Does someone know a practical way of doing this in Matlab, especially some source code samples / Toolboxes for mesh segmentation and/or 3d primitive approximation?
Until know, I have found an tried:
- Learning-Mesh-Segmentation, (I dont have the computing ressources to train the model), from here
- ddcrpMeshSegmentation, requires multiple moved versions of the same model, from here
- K-means, modified from this blog
- some graph partitioning functions, many available, eg. here
Out of those, K-means looks somewhat promising and maybe some graph partitioning might also help. For the following primitive approximation, minBoundEllipsoids seems like a good way to extract orientations from the segments to me. I appreciate comments on that too.
Thank you very much
1 个评论
Lorenzo Pollicini
2024-10-16
Hello @maho, did you find a solution for your problem? I am also dealing with the same task at the moment.
回答(1 个)
TED MOSBY
2024-11-14,14:35
编辑:TED MOSBY
2024-11-18,19:51
To segment a mesh into coherent regions you can try one of these methods:
1. K-means clustering: Use the built-in ‘kmeans’ function.
2. Graph Partitioning: You can use MATLAB's ‘graph’ or ‘digraph’ functions for this purpose.
3. Spectral clustering: it uses the eigenvectors of a graph Laplacian to perform clustering.
www.mathworks.com/help/stats/spectral-clustering.html?searchHighlight=spectral%20clustering&s_tid=srchtitle_support_results_1_spectral%2520clustering[UN1]
Now after you are done with the segmentation, to fit primitive shapes in each segment, you can:
- For cuboids: Use bounding box algorithms. MATLAB's ‘regionprops3’ function can be useful for 3D data.
- www.mathworks.com/help/images/ref/regionprops3.html?s_tid=doc_ta
- For cylinders and spheres and ellipsoids: Use least squares fitting.
- www.mathworks.com/help/curvefit/least-squares-fitting.html?searchHighlight=least%20squares%20fit&s_tid=srchtitle_support_results_1_least%2520squares%2520fit
You can follow the above steps like in an example workflow here:
% Load mesh data (vertices and faces)
[vertices, faces] = readObj('your_mesh_file.obj');
% Compute normals or other features
normals = computeNormals(vertices, faces);
% Apply K-means clustering
numClusters = 5;
[idx, C] = kmeans(normals, numClusters);
% Visualize segmentation
trisurf(faces, vertices(:,1), vertices(:,2), vertices(:,3), idx);
% Fit primitives to each segment
for i = 1:numClusters
segmentIndices = (idx == i);
segmentVertices = vertices(segmentIndices, :);
% Fit a bounding box or other primitive
bbox = fitBoundingBox(segmentVertices); %custom function, make on your own
plotBoundingBox(bbox);%custom function, make on your own
end
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!