Im2mesh (2D image to triangular meshes)

Version 1.85 (585 KB) by Jiexian Ma
Convert 2d multi-phase image to finite element meshes, with poly-line simplification feature.
1.3K Downloads
Updated 14 Jan 2023

View License

This tool consists of a few functions, e.g., im2mesh, im2Bounds (image to polygonal boundaries), getCtrlPnts (mark intersecting vertex between polygons), 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, compatible with COMSOL), 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'.
Notes
If you have any questions or suggestions, feel free to send me an email.
mjx0799@gmail.com, Jan 2023.
Acknowledgments
Great thanks Dr. Yang Lu providing valuable advice on this tool.

Cite As

Jiexian Ma (2024). 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
Categories
Find more on Convert Image Type in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.85

Add comments & description

1.84

Revise Description

1.83

Revise summary

1.82

Update description

1.81

Update description

1.80

Add im2meshBuiltIn.m, poly2meshBuiltIn.m
Update examples

1.76

improve getCtrlPnts
faster

1.75

Add new parameter 'select_phase'

1.71

Revise description

1.7

Add two new parameters for mesh generation

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

0.6.0