File Exchange

image thumbnail

Im2mesh (2D image to triangular meshes)

version 1.6 (117 KB) by Jiexian Ma
Convert 2d multi-phase image to FEM meshes, with poly-line simplification feature.

25 Downloads

Updated 23 May 2020

View License

This tool consists of a few functions, like, im2Bounds (image to polygonal boundaries), getCtrlPnts (mark intersecting vertex between polygons, serving as fixed point for polygon simplification and meshing), simplifyBounds (simplify polygon), poly2mesh (polygon to triangular meshes), getInterf (search nodes at interface), printInp (export as Inp file), and printBdf (export as Bdf file).

Features
- Exactly reserve the contact detail between different phases.
- Able to avoid sharp corners when simplifying polyline.
- Generated mesh can be exported as inp file (Abaqus), bdf file (Nastran bulk data), and .node/.ele file.
- 5 examples are presented in demo1.m ~ demo5.m.

Note: To make this code run (especially for poly2mesh), you need to download MESH2D from https://www.mathworks.com/matlabcentral/fileexchange/25555-mesh2d-delaunay-based-unstructured-mesh-generation, and add the folder (mesh2d-master) to your path. After that, you can start with demo1.m~demo5.m in im2mesh. Check the images in the folder (im2mesh\images\...).

If you have any questions or suggestions, feel free to send me an email.
mjx0799@gmail.com, May 2020.

Acknowledgments
Great thanks Dr. Yang Lu providing valuable advice to this tool.  

Cite As

Jiexian Ma (2020). Im2mesh (2D image to triangular meshes) (https://www.mathworks.com/matlabcentral/fileexchange/71772-im2mesh-2d-image-to-triangular-meshes), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

sgericeb

Hello, I have tried to add the folder mesh2d-master to the path but I cannot find any such folder anywhere. Can anyone help with this?
Thanks

CHENG LUO

Jiexian Ma

@chunfeng hi chunfeng, you can send me an email with your images.

chunfeng

Hello, I especially want to know how the demo pictures are processed. When I use your algorithm to process my pictures, both the accuracy and efficiency are not satisfactory, I hope to get your guidance,Thank you

Excellent very useful. Is it possible to export files in Triangle (Shewchuk) format? .node, .ele, .edge. If so can this include boundary, node and element attributes?

Jiexian Ma

@chunfeng: Yes, that's the purpose of this tool. However, for large images (>1000*1000), it takes some time to get the meshing result. Check the latest version. I add some examples. About boundary conditions, check the comments that I wrote in printInp_multiPart.m. Boundary node numbers of each material is extracted. Node set and node-based surface at boundary of each material are defined in the exported inp file. Since the node-based surface is not supported in Abaqus CAE, you might need to read the documentation of Abaqus about how to use inp file to define boundary conditions and constraints.

chunfeng

Hello, I want to know if this method can accurately define the mesh of boundary intersection of different materials to make the boundary smoother. In addition, does the number and node generated by this method satisfy the finite element calculation? The boundary node numbers of different materials can be extracted separately and used to impose boundary conditions in the finite element?

Seth

@Jiexian: Got it! This is helpful - thanks. FYI: I have tweaked it to just select which specific gray levels we want to mesh (and which to ignore).

Nice work and helpful code. Thanks!

Jiexian Ma

@Seth, yep, I know your meaning.
You can replace line 19 to 21 in im2Bounds.m with following code. It should work.
nlevels = 1;
bounds = cell( 1, nlevels );
intensity = max(max(im));

Seth

Is there a simple way to provide the mesh of just a single object in the image instead of meshing the full image space? For example, you provide an example image titled "a1.tif". Is it easy to just mesh the white object instead of both the white and black space? (Say I wanted to build a solid model in Abaqus of this white object, but the black color is just air and is not usually modeled).

This may also be helpful in the cases of very large images that require a long time to mesh. In that case, I don't want to waste resources on meshing the background of the image.

Many thanks!

I tried the code by running the "demo.m" file. There is an Abaqus input file, "test.inp", generated. However, when I import the inp file to ABAQUS CAE or Hypermesh, both of them complain about errors. Would you please double check the formatting of the inp file?

Updates

1.6

make im2Bounds() more readable using getExactBounds()

1.5

improve im2Bounds.m and getCtrlPnts.m
significantly faster

1.1.1

update description

1.1

revise demo(), add examples
add several functions, like printInp_multiPart(), printInp_multiSect(), printBdf()

0.9

Improve time efficiency of getCtrlPnts(). Faster. Add new parameter - tf_avoid_sharp_corner. Able to avoid non-convergence when meshing.
Rewrite getNodeEle(). Using global numbering.
Revise printInp(). Add new parameter - precision_nodecoor.

0.8.2

new image for cover

0.8.1

revise getCtrlPnts() for time efficiency

0.8.0

debug
revise printInp(), support linear element and quadratic element
revise im2Bounds() and bwperimtrace(), for 4-connected neighbourhood
able to clear up redundant vertices that are brought about by delZeroAreaPoly

0.7.0

debug
reorganize part of the code, increase readability
revise some comments
add calculation of polygon's area, polygon with zero area will be deleted automatically
update examples

0.6.2

update description

0.6.1

update description

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux