({{, (RefLink[ImageMesh, paclet:ref/ImageMesh])[image] 
returns the foreground region in image as a (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]) object.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ImageMesh, paclet:ref/ImageMesh]) is also known as image-based meshing and converts 2D or 3D image data such as MRI or CT to a computer model. Constructed models can be used in a variety of ways, including finite elements methods (FEMs) for solving PDEs.

(RefLink[ImageMesh, paclet:ref/ImageMesh]) works with arbitrary 2D and 3D images, taking the nonzero pixels of the image as foreground.

(RefLink[ImageMesh, paclet:ref/ImageMesh]) has the same options as (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]), with the following changes and additions:

In 2D, possible settings for (RefLink[Method, paclet:ref/Method]) include:

In 3D, possible settings for (RefLink[Method, paclet:ref/Method]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (10)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Convert a 2D shape to a boundary mesh:

ImageMesh[]

Convert a 3D image into mesh:

ImageMesh[]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)CornerNeighbors  (1)

By default, 8-connectivity is assumed:

ImageMesh[,CornerNeighbors->True]

Assume 4-connectedness:

ImageMesh[,CornerNeighbors->False]

OpenersExampleSubsection1(Spacer1)Method  (2)

Exact boundary:

ImageMesh[,Method->"Exact"]

Shape computed using marching squares:

ImageMesh[,Method->"MarchingSquares"]

Use the linear separable method:

ImageMesh[,Method->"LinearSeparable"]

By default, the exact method is used for 3D volumes:

vol=;

ImageMesh[vol]

Use marching cubes:

ImageMesh[vol,Method->"MarchingCubes"]

Use dual marching cubes:

ImageMesh[vol,Method->"DualMarchingCubes"]

OpenersExampleSection3(Spacer1)Applications  (4)

Upsample an image by first approximating its smoothed shape and then rasterizing:

i=;

Rasterize[ImageMesh[i,ImageSize->300,Background->Black,BaseStyle->White],"Image"]

Compare with the magnified version of the image:

Image[i,ImageSize->300]

Segment a part of an image and convert it to a mesh:

i=;

b=DeleteSmallComponents[Binarize[i,{0,.3}]]

ImageMesh[b]

Obtain an image of the Great Salt Lake:

img=EntityValue[(Entity["Great Salt Lake", Entity["Lake","GreatSaltLake::yw8cf"], "Entity[\"Lake\", \"GreatSaltLake::yw8cf\"]", "lake"]),"Image"]

Regularize the image with a mean shift filter:

img2=MeanShiftFilter[img,3,0.1]

Obtain a segmentation via region growing:

mask=RegionBinarize[img2,,1/5]

Create a mesh of the lake surface:

Ω=ImageMesh[mask]

Compute the eigenfunctions of the wave equation on Ω:

{vals,funs}=NDEigensystem[
{-Laplacian[u[x,y],{x,y}],DirichletCondition[u[x,y]==0,True]},u[x,y],{x,y}∈Ω,6];

Display the oscillation modes:

GraphicsGrid@Partition[Table[ContourPlot[funs[[i]],{x,y}∈Ω,PlotRange->All,PlotLabel->vals[[i]],PlotTheme->"Minimal"],{i,Length[vals]}],3]

Create 3D-printable objects from 2D images:

i=;

ImageMesh[ColorNegate[i]]

RegionProduct[%,Line[{{0.},{50.}}]]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

A shape typically has a more compact representation when converted to a mesh:

i=;

ByteCount[i]

ByteCount[ImageMesh[i]]

Even with exact representation, the shape is slightly simplified:

ByteCount[ImageMesh[i,Method->"Exact"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Image, paclet:ref/Image])  ▪  (RefLink[ArrayMesh, paclet:ref/ArrayMesh])  ▪  (RefLink[MeshRegion, paclet:ref/MeshRegion])  ▪  (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Feature Detection, paclet:guide/FeatureDetection])}, {▪(RefLinkPlain[Mesh-Based Geometric Regions, paclet:guide/MeshRegions])}, {▪(RefLinkPlain[Computer Vision, paclet:guide/ComputerVision])}, {▪(RefLinkPlain[Geometric Computation, paclet:guide/GeometricComputation])}})}})