Im2mesh (2D image to finite element mesh)

Version 2.47 (19.3 MB) by Jiexian Ma
Generate finite element mesh based on 2D multi-phase image. For image-based finite element analysis.
1.5K Downloads
Updated 28 Aug 2025
GUI version: Im2mesh_GUI
Standalone desktop application: Installer (No need to install MATLAB)
Im2mesh is an open-source MATLAB/Octave package for generating finite element mesh based on 2D segmented multi-phase image. It provides a robust workflow capable of processing various input images, such as microstructure images of engineering materials. Due to its generalized framework, Im2mesh can handle segmented image with more than 10 phases.
Im2mesh can also be used as a mesh generation interface for MATLAB 2D multi-part geometry, aka multi-domain or multi-phase geometry (see demo14-17).
News
  • Version 2.45 can export polygonal boundaries extracted from image as dxf file (CAD).
  • Function plotMeshes become more powerful, providing a few plot style settings (see demo08).
  • Version 2.2.0 supports using Gmsh as mesh generator (unstructured quadrilateral mesh).
  • Version 2.1.6 updates the DOI. Im2mesh is now citable.
Features
  • Accurately preserve the contact details between different phases.
  • Incorporates polyline smoothing and simplification
  • Able to edit polygonal boundary before mesh generation.
  • Support phase selection and local mesh refinement.
  • 4 mesh generators are available for selection: MESH2D, generateMesh, Gmsh, and pixelMesh.
  • Graphical user interface (GUI) version is available as a MATLAB app and as a standalone desktop application.
Generated mesh can be exported as
  • inp file with boundary node set (Abaqus)
  • bdf file (Nastran bulk data, compatible with COMSOL),
  • msh file (Gmsh mesh format)
  • stl file
  • MATLAB PDE model object
  • For other formats (such as vtk), you can import the generated msh file into software Gmsh and then export.
How to start
After downloading Im2mesh package, I suggest you start with Im2mesh_GUI app in the folder, which will help you understand the workflow and parameters of Im2mesh. A detailed tutorial is provided in Im2mesh_GUI Tutorial.pdf.
Then, you can learn to use Im2mesh package in the folder "Im2mesh_Matlab" or "Im2mesh_Octave". 16 examples are provided.
  • If you're using MATLAB, examples are live script mlx files (demo01.mlx ~ demo18.mlx). If you find some text in the mlx file is missing, please read the html file instead. Note that demo02.mlx requires MATLAB Partial Differential Equation (PDE) Toolbox. If you don't have PDE Toolbox, you can skip demo02.mlx.
  • If you're using Octave, examples are m files (demo1.m ~ demo10.m).
  • Examples are also available as html files in the folder "demo_html".
Examples
  • demo01 - Demonstrate function im2mesh, which use MESH2D as mesh generator.
  • demo02 - Demonstrate function im2meshBuiltIn, which use MATLAB built-in function generateMesh as mesh generator.
  • demo03 - Export: save mesh as inp, bdf, msh, and stl file; save geometry as geo file or PSLG data.
  • demo04 - What is inside im2mesh.
  • demo05 - Avoid sharp corner
  • demo06 - Thresholds in polyline smoothing
  • demo07 - Parameter hmax and grad_limit in mesh generation
  • demo08 - Function plotMeshes
  • demo09 - How to select phases for meshing
  • demo10 - Different polyline smoothing techniques
  • demo11 - Find node sets at the interface and boundary
  • demo12 - Function pixelMesh (pixel-based quadrilateral mesh)
  • demo13 - Use Gmsh as mesh generator
  • demo14 - Use polyshape to define geometry for mesh generation
  • demo15 - Edit polygonal boundaries before meshing
  • demo16 - Add mesh seeds/nodes
  • demo17 - Refine mesh
  • demo18 - Create tetrahedral mesh based on 2d image
Notes
Im2mesh package identifies different phases in a image by their grayscales. Different grayscales correspond to different phases. If you have 4 level of grayscales in a image, the resulted meshes will contain 4 phases.
Acknowledgments
Many thanks to Dr. Yang Lu for providing valuable suggestions and testing of export formats.
This project incorporates code from the following open-source projects. I appreciate the contributions of the original authors. Each incorporated code retains its original copyright.

Cite As

Ma, Jiexian, and Yuanyuan Li. Im2mesh: A MATLAB/Octave Package for Generating Finite Element Mesh Based on 2D Multi-Phase Image. Zenodo, 2025, https://doi.org/10.5281/ZENODO.14847059.

View more styles

Once my paper is published, I will update a new DOI here.

MATLAB Release Compatibility
Created with R2021b
Compatible with R2017b and later releases
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!

Im2mesh_Matlab

Im2mesh_Matlab/mesh2d-master

Im2mesh_Matlab/mesh2d-master/aabb-tree

Im2mesh_Matlab/mesh2d-master/geom-util

Im2mesh_Matlab/mesh2d-master/hfun-util

Im2mesh_Matlab/mesh2d-master/hjac-util

Im2mesh_Matlab/mesh2d-master/mesh-ball

Im2mesh_Matlab/mesh2d-master/mesh-cost

Im2mesh_Matlab/mesh2d-master/mesh-file

Im2mesh_Matlab/mesh2d-master/mesh-util

Im2mesh_Matlab/mesh2d-master/poly-test

Im2mesh_Matlab/test_script

Im2mesh_Octave

Im2mesh_Octave/mesh2d-master

Im2mesh_Octave/mesh2d-master/aabb-tree

Im2mesh_Octave/mesh2d-master/geom-util

Im2mesh_Octave/mesh2d-master/hfun-util

Im2mesh_Octave/mesh2d-master/hjac-util

Im2mesh_Octave/mesh2d-master/mesh-ball

Im2mesh_Octave/mesh2d-master/mesh-cost

Im2mesh_Octave/mesh2d-master/mesh-file

Im2mesh_Octave/mesh2d-master/mesh-util

Im2mesh_Octave/mesh2d-master/poly-test

Version Published Release Notes
2.47

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.47

2.45

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.45

2.42

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.42

2.40

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.40

2.36

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.36

2.35

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.35

2.33

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.33

2.30

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.30

2.26

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.26

2.2.3

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/v2.2.3

2.2.1

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.2.1

2.2.0

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.2.0

2.1.9

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.9

2.1.8

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.8

2.1.6

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.6

2.1.5

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.5

2.1.1

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.1

2.1.0

See release notes for this release on GitHub: https://github.com/mjx888/im2mesh/releases/tag/2.1.0

1.88

Update Description

1.87

Update Description

1.86

add note

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

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.