Im2mesh (2D image to triangular meshes)

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

777 Downloads

Updated 30 Aug 2022

View License

This tool consists of a few functions, like, im2mesh, 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, 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.
  • Support phase selection before meshing (see demo10.m)
  • Generated mesh can be exported as inp file (Abaqus), bdf file (Nastran bulk data), and .node/.ele file.
  • 10 examples are presented in demo1.m ~ demo10.m.
Examples
  • demo1.m - Demonstrate function im2meshBuiltIn, which use matlab built-in function generateMesh() to generate mesh from geometry.
  • demo2.m - Demonstrate function im2mesh, which use MESH2D to generate mesh from geometry.
  • demo3.m - Demonstrate how to export mesh as inp, bdf, and .node/.ele file.
  • demo4.m - Demonstrate what is inside function im2mesh.
  • demo5.m - Demonstrate the case of 'tolerance = eps'.
  • demo6.m and demo7.m - Demonstrate parameter 'tolerance'.
  • demo8.m - Demonstrate parameter 'tf_avoid_sharp_corner'.
  • demo9.m - Demonstrate parameter 'grad_limit'.
  • demo10.m - Demonstrate parameter 'select_phase'.
Note: To make demo2.m~demo10.m run, 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 demo2.m~demo10.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, Aug 2022.
Acknowledgments
Great thanks Dr. Yang Lu providing valuable advice on this tool.

Cite As

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

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

Community Treasure Hunt

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

Start Hunting!