Azzera filtri
Azzera filtri

How to make 2D binary mask from the triangle mesh in Matlab?

6 visualizzazioni (ultimi 30 giorni)
At the beginning I imported triangle mesh ( which contain about a thousand of triangles) to Matlab. For now I have two mat files , first with the coordinates of triangles vertices example part of file:
-13,91810 -13,63370 -13,91810 ...
128,4240 122,7110 122,7110 ...
-41,85760 -41,94330 -41,85760 ....
Second with the indices of nodes that make up the triangles example part of file:
1 4 7 ...
2 5 8 ...
3 6 9 ...
So i have a 3D triangle mesh and what I try to do is 2D binary mask (mask=ones , background =zeros) from a section of this mesh. I consider something like projection to 2d plane and than use something like inpolygon function. But I'm rather novice and for now I don't know how to deal with it. I will appreciate every help.

Risposte (2)

Image Analyst
Image Analyst il 1 Mag 2014
Does each row contain all the (x,y,z) coordinates of a single triangle? If so, then there should be 9 coordinates: 3 x, 3 y, and 3 z. Or does each group of 3 lines represent a triangle, so that one line represents only one (x,y,z) coordinate of one vertex?
And could you do it numerically, projecting the points down onto a digital matrix/image? If so, this is easy. If you have the Image Processing Toolbox, you can just use poly2mask to make a binary image of one triangle and then for each subsequent triangle, just OR it in. You just need to decide on an image resolution, say 5000 by 5000 to cover the range of -45 to +150 in x and y.
If you need an analytical solution, then that's harder because for two overlapping triangles you'd have to find the 6 points where the two triangles intersect.

Kevin
Kevin il 14 Mar 2015
Modificato: Kevin il 14 Mar 2015
I have got a similar problem, I'm using MESH2D in Matlab in order to mesh ROI (Region Of Interest) from images. Now I would like to make binary masks from these triangular meshes. The outputs from [p,t] = mesh2d(node) are:
  • p = Nx2 array of nodal XY co-ordinates.
  • t = Mx3 array of triangles as indicies into P, defined with a counter-clockwise node ordering.Example of my initial code (feel free to improve it!):
mask= logical([0 0 0 0 0; 0 1 1 0 0; 0 1 1 1 1; 0 1 1 0 0]) %let's say this is my ROI
figure, imagesc(mask)
lol=regionprops(mask,'all')
[p,t] = mesh2d(lol.ConvexHull); %it should mesh the ROI
How can I make masks from this triangular mesh?
Thank you in advance!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by