Turn image mask into triangular mesh
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to run a FEM model on some images, and I need to first create a mesh to run the model in. The images are very high-resolution, and I essentially just want a non-redundant list of each of the corners of the pixels in the domain I care about. I have tried using the find() function to locate the x,y position of each pixel, and then find the location of its corners, but it is very slow iterating through the entire list of white pixels. I am thinking using delaunayTriangulation will be faster, but currently it creates triangles outside of the mesh I care about. How can I prevent the delaunay function from making triangles outside of the list of pixels?
Or is there an easier way to triangulate these pixels? Can I limit the length of the boundary/area, removing those extraneous triangular elements?
1 comentario
Trang Cao
el 28 de Mayo de 2024
Probably you don't need the answer for this anymore but I was just looking for the answer to a similar question, i.e., delaurayTriangulation do not behave well on non-convex shape.
I found alphaShape and then alphaTriangulation.
Hope this may help someone else...
Respuestas (1)
Satwik
el 21 de Ag. de 2024
Hi,
I understand that you are working with high-resolution images and want to create a finite element mesh that accurately covers only the relevant parts of these images. You are exploring ‘delaunayTriangulation’ but facing issues with unwanted triangles forming outside your area of interest. Your goal is to limit the mesh to the specific region and remove extraneous triangles. To efficiently create a mesh aligned with your region of interest, you can use ‘delaunayTriangulation’ more effectively by incorporating boundary constraints. Here is an example of how you can do this:
1. Extract Boundary Points: Identify the boundary of your region of interest using boundary tracing (‘bwboundaries’ in MATLAB).
% Extract boundary points from a binary image
boundaryPts = bwboundaries(yourBinaryImage);
boundaryPts = boundaryPts{1}; % If multiple boundaries, choose the relevant one
2. Constrained Delaunay Triangulation: Use ‘delaunayTriangulation’ with constraints to ensure the triangulation respects your region's boundaries.
% Define boundary edges
boundaryEdges = [(1:length(boundaryPts)-1)', (2:length(boundaryPts))'];
boundaryEdges = [boundaryEdges; length(boundaryPts), 1]; % Close the loop
% Create a Delaunay triangulation with constraints
dt = delaunayTriangulation(boundaryPts, boundaryEdges);
3. Filter Out Unwanted Triangles: After triangulation, filter out triangles outside the region of interest by checking the centroids of the triangles with ‘inpolygon’.
% Calculate the centroids of triangles
triCenters = incenter(dt);
% Check if the centroids are inside the boundary
inside = inpolygon(triCenters(:,1), triCenters(:,2), boundaryPts(:,1), boundaryPts(:,2));
% Retain only the triangles that are inside
validTriangles = dt.ConnectivityList(inside, :);
Here are some documentation links for the functions used in the above example, which you may refer:
- https://www.mathworks.com/help/matlab/ref/delaunaytriangulation.html
- https://www.mathworks.com/help/images/ref/bwboundaries.html
- https://www.mathworks.com/help/matlab/ref/inpolygon.html
- https://www.mathworks.com/help/matlab/ref/triangulation.incenter.html
I hope this helps to give you direction in achieving your goals.
0 comentarios
Ver también
Categorías
Más información sobre Delaunay Triangulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!