({{, (RefLink[RegionImage, paclet:ref/RegionImage])[reg] 
returns a rasterized grayscale 2D or 3D image of reg.}, {, (RefLink[RegionImage, paclet:ref/RegionImage])[reg,{{(Subscript[x, min]),(Subscript[x, max])},…}]
restricts to the bounds [(Subscript[x, min]),(Subscript[x, max])]×⋯.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[RegionImage, paclet:ref/RegionImage]) converts regions to 2D and 3D raster images.

The region reg can be anything that is (RefLink[ConstantRegionQ, paclet:ref/ConstantRegionQ]) and a (RefLink[RegionEmbeddingDimension, paclet:ref/RegionEmbeddingDimension]) of 2 or 3.

The following options can be specified:

By default, an automatic thickness is chosen to draw lower-dimensional regions. With (RefLink[Method, paclet:ref/Method])->{"Thickness"->t}, these regions are rasterized using the absolute thickness t.

OpenersPrimaryExamplesSection(Spacer1)Examples  (25)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Rasterize a region in 2D:

RegionImage[Annulus[]]

Rasterize a region in 3D:

RegionImage[Cone[]]

OpenersExampleSection1(Spacer1)Scope  (7)

OpenersExampleSubsection0(Spacer1)Data  (5)

Rasterize a (RefLink[Region, paclet:ref/Region]):

RegionImage[Region[DiskSegment[{0,0},1,{π/6,π-π/6}]]]

Rasterize a (RefLink[MeshRegion, paclet:ref/MeshRegion]):

RegionImage[]

Rasterize a (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]):

ℛ=BoundaryMeshRegion[
{{0,0},{3,0},{3,3},{0,3},{1,1},{2,1},{2,2},{1,2}},Line[{1,2,3,4,1}],Line[{5,6,7,8,5}]
]

RegionImage[ℛ]

Rasterize a region in 2D with components of 0, 1, and 2 dimensions:

region =Region@RegionUnion[Annulus[],Circle[{0,0},4/3],Point[{0,0}]]

RegionImage[region]

Rasterize a region in 3D with mixed dimensional components:

region = Region@ParametricRegion[{{x,y,z+y x},(x^2)+(y^2)+(z^2)<=1  ∨ z==Sin[x+y] ∨ (x==0 ∧ y==0)},{{x,-1,1},{y,-1,1},{z,-1,1}}
]

RegionImage[region]

OpenersExampleSubsection1(Spacer1)Parameters  (2)

Rasterize the part of a region in 2D that is within specified bounds:

RegionImage[Disk[],{{0,1},{0,1}}]

Rasterize the part of a region in 3D that is within specified bounds:

RegionImage[Sphere[],{{-1,1},{-1/2,1},{-1,-1/3}}]

OpenersExampleSection2(Spacer1)Options  (6)

OpenersExampleSubsection2(Spacer1)Method  (4)

OpenersExampleSubsubsection0(Spacer1)"Thickness"  (4)

Compare different settings for the thickness of components that are not full dimensional:

mesh = DiscretizeRegion[ImplicitRegion[x==0∧y==0 ∨ 1/4≤(x^2)+(y^2)≤1 ∨ (x^2)+(y^2)==16/9,{x,y}]
]

Table[
Labeled[
RegionImage[mesh,RasterSize-> 100,Method->{"Thickness"->t}],
Text[t]],{t,{0.5,1,2,4,8,16}}
]

The thickness is effectively the width of a feature in pixels:

bounds ={{-1.2,1.2},{-1.2,1.2}};
mesh = MeshRegion[
{{0,0},{-1,0},{0,-1},{1,0},{0,1},{1/2,1/2}},
{Line[{2,1,3,4,1,5}],Point[{6}]},
BaseStyle->Thick
]

Table[
Labeled[
RegionImage[mesh,bounds,RasterSize->24,ImageSize->100,Method->{"Thickness"->t}],
Text[t]
],
{t,3}
]

The default "Thickness"->(RefLink[Automatic, paclet:ref/Automatic]) renders one white pixel per (RefLink[Point, paclet:ref/Point]):

n = 50;
mesh = MeshRegion[RandomPoint[Disk[],n],Point[Range[n]]];

Table[
Labeled[
RegionImage[mesh, {{-1,1},{-1,1}}, Method->{"Thickness"->t},RasterSize-> 100],
Text[t]
],
{t,{Automatic,0,1,2,4,8}}
]

Thicken a shell in 3D:

RegionImage[
Sphere[],
{{-1,1},{-1/2,1},{-1,-1/3}},
Method->{"Thickness"->4}
]

OpenersExampleSubsection3(Spacer1)RasterSize  (2)

By default, regions are rasterized to the default graphics raster size:

RegionImage[Annulus[]]

ImageDimensions[%]

Specify the raster size:

RegionImage[Annulus[],RasterSize->100]

ImageDimensions[%]

Use (RefLink[ImageSize, paclet:ref/ImageSize]) to specify the display size:

RegionImage[Annulus[],ImageSize->100]

ImageDimensions[%]

OpenersExampleSection3(Spacer1)Applications  (6)

Create the image of a Sierpiński mesh:

RegionImage[SierpinskiMesh[6]]

Rasterization of a 3D knot:

i=RegionImage[KnotData["Trefoil","Region"]]

ListAnimate[Image3DSlices[i]]

Generate cylindric masks for a volume:

vol=ExampleData[{"TestImage3D","CTengine"}]
dims=ImageDimensions[vol];

mask=Blur[RegionImage[
Region@Cylinder[{{-100,0,0},{100,0,0}},50],Outer[Times,dims,{-1,1}/2],
 RasterSize->dims
]]

ImageMultiply[vol,mask]

Construct a 3D image from elevation data around Mount Everest:

everest=GeoElevationData[(Entity["Mount Everest", Entity["Mountain","MountEverest"], "Entity[\"Mountain\", \"MountEverest\"]", "mountain"]),Automatic,"Region"]

RegionImage[everest]

Generate the volume of a polyhedron:

ico=BoundaryMeshRegion@@First[PolyhedronData["Icosahedron"]]

RegionImage[ico]

"Melting" a snowflake region via curvature flow:

flake=RegionImage[]

corn=CurvatureFlowFilter[flake,16]

ImageMesh[corn]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

Setting the thickness to zero effectively ignores the lower-dimensional components:

RegionImage[Circle[],Method->{"Thickness"->0}]

Increase the thickness to get response for lower-dimensional components:

RegionImage[Circle[],Method->{"Thickness"->1}]

3D rasterization can show a moiré-like effect due to the partial volume computation and coloring:

vol=RegionImage[Sphere[],{{-1,1},{-1/2,1},{-1,-1/3}},
Method-> {"Thickness"->2}]

Use a color function that changes only opacities based on the voxel intensity, not the color:

vol2=Image3D[vol,ColorFunction->(GrayLevel[1,#]&),Background->Black]

Antialiasing using blur:

Blur[vol2]

Antialiasing would even improve a color function that changes both color and opacity by voxel intensities:

Blur[vol]

OpenersExampleSection5(Spacer1)Neat Examples  (2)

Estimate the area content of a rasterized disk:

img=RegionImage[
BoundaryDiscretizeRegion[Disk[],PrecisionGoal->8],{{-1.2,1.2},{-1.2,1.2}},
RasterSize-> 32
]

pixelSize = 2.4/32;

Compare the area estimate with the disk area π:

area=ImageMeasurements[img,"Total"] (pixelSize^2)

area/π

Nested conversion between a discretized and mesh representation of a disk:

mesh=BoundaryDiscretizeRegion[Disk[]]

Nest[
ImageMesh[
RegionImage[#,{{-1,1},{-1,1}}],
DataRange->{{-1,1},{-1,1}}
]&,
mesh,
100
]

Show the evaluation:

NestList[
ImageMesh[
RegionImage[#,{{-1,1},{-1,1}}],
DataRange->{{-1,1},{-1,1}}
]&,
mesh,
100
][[1;;-1;;25]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DiscretizeRegion, paclet:ref/DiscretizeRegion])  ▪  (RefLink[DiscretizeGraphics, paclet:ref/DiscretizeGraphics])  ▪  (RefLink[Rasterize, paclet:ref/Rasterize])  ▪  (RefLink[ImageMesh, paclet:ref/ImageMesh])  ▪  (RefLink[MeshRegion, paclet:ref/MeshRegion])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Creating & Importing Images, paclet:guide/CreatingAndImportingImages])}})}})