---
title: "RegionImage"
language: "en"
type: "Symbol"
summary: "RegionImage[reg] returns a rasterized grayscale 2D or 3D image of reg. RegionImage[reg, {{xmin, xmax}, ...}] restricts to the bounds [xmin, xmax]*\\[CenterEllipsis]."
keywords: 
- rasterizing region
- rasterizing mesh region
- rasterizing 2D mesh
- rasterizing 3D mesh
- grid a region
- numericalize region
- discretize a region
- sample a region
- convert region to image
- region to image
canonical_url: "https://reference.wolfram.com/language/ref/RegionImage.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Creating & Importing Images"
    link: "https://reference.wolfram.com/language/guide/CreatingAndImportingImages.en.md"
  - 
    title: "Image Computation: Update History"
    link: "https://reference.wolfram.com/language/guide/ImageComputation-UpdateHistory.en.md"
related_functions: 
  - 
    title: "DiscretizeRegion"
    link: "https://reference.wolfram.com/language/ref/DiscretizeRegion.en.md"
  - 
    title: "DiscretizeGraphics"
    link: "https://reference.wolfram.com/language/ref/DiscretizeGraphics.en.md"
  - 
    title: "Rasterize"
    link: "https://reference.wolfram.com/language/ref/Rasterize.en.md"
  - 
    title: "ImageMesh"
    link: "https://reference.wolfram.com/language/ref/ImageMesh.en.md"
  - 
    title: "MeshRegion"
    link: "https://reference.wolfram.com/language/ref/MeshRegion.en.md"
---
# RegionImage

RegionImage[reg] returns a rasterized grayscale 2D or 3D image of reg.

RegionImage[reg, {{xmin, xmax}, …}] restricts to the bounds $\left[x_{\text{\textit{min}}},x_{\text{\textit{max}}}\right]\times \cdots$.

## Details and Options

* ``RegionImage`` converts regions to 2D and 3D raster images.

* The region ``reg`` can be anything that is ``ConstantRegionQ`` and a ``RegionEmbeddingDimension`` of 2 or 3.

* The following options can be specified:

|                 |           |                                                   |
| --------------- | --------- | ------------------------------------------------- |
| ImageResolution | Automatic | image resolution in DPI for rasterization         |
| ImageSize       | Automatic | final displayed image size in printer's points    |
| MetaInformation | <\|\|>    | metainformation to be included in the image       |
| Method          | Automatic | method parameters to use                          |
| RasterSize      | Automatic | raster size in pixels or voxels for rasterization |

* By default, an automatic thickness is chosen to draw lower-dimensional regions. With ``Method -> {"Thickness" -> t}``, these regions are rasterized using the absolute thickness ``t``.

---

## Examples (25)

### Basic Examples (2)

Rasterize a region in 2D:

```wl
In[1]:= RegionImage[Annulus[]]

Out[1]= [image]
```

---

Rasterize a region in 3D:

```wl
In[1]:= RegionImage[Cone[]]

Out[1]= [image]
```

### Scope (7)

#### Data (5)

Rasterize a ``Region`` :

```wl
In[1]:= RegionImage[Region[DiskSegment[{0, 0}, 1, {π / 6, π - π / 6}]]]

Out[1]= [image]
```

---

Rasterize a ``MeshRegion`` :

```wl
In[1]:= RegionImage[[image]]

Out[1]= [image]
```

---

Rasterize a ``BoundaryMeshRegion`` :

```wl
In[1]:=
ℛ = 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}]
	]

Out[1]= [image]

In[2]:= RegionImage[ℛ]

Out[2]= [image]
```

---

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

```wl
In[1]:= region  = Region@RegionUnion[Annulus[], Circle[{0, 0}, 4 / 3], Point[{0, 0}]]

Out[1]= [image]

In[2]:= RegionImage[region]

Out[2]= [image]
```

---

Rasterize a region in 3D with mixed dimensional components:

```wl
In[1]:=
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}}
	]

Out[1]= [image]

In[2]:= RegionImage[region]

Out[2]= [image]
```

#### Parameters (2)

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

```wl
In[1]:= RegionImage[Disk[], {{0, 1}, {0, 1}}]

Out[1]= [image]
```

---

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

```wl
In[1]:= RegionImage[Sphere[], {{-1, 1}, {-1 / 2, 1}, {-1, -1 / 3}}]

Out[1]= [image]
```

### Options (6)

#### Method (4)

##### "Thickness" (4)

---

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

```wl
In[1]:=
mesh = DiscretizeRegion[ImplicitRegion[x == 0∧y == 0 ∨ 1 / 4 ≤ x^2 + y^2 ≤ 1 ∨ x^2 + y^2 == 16 / 9, {x, y}]
	]

Out[1]= [image]

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

Out[2]= {Labeled[[image], Text[0.5]], Labeled[[image], Text[1]], Labeled[[image], Text[2]], Labeled[[image], Text[4]], Labeled[[image], Text[8]], Labeled[[image], Text[16]]}
```

---

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

```wl
In[1]:=
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
	]

Out[1]= [image]

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

Out[2]= {Labeled[[image], Text[1]], Labeled[[image], Text[2]], Labeled[[image], Text[3]]}
```

---

The default ``"Thickness" -> Automatic`` renders one white pixel per ``Point`` :

```wl
In[1]:=
n = 50;
mesh = MeshRegion[RandomPoint[Disk[], n], Point[Range[n]]];

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

Out[2]= {Labeled[[image], Text[Automatic]], Labeled[[image], Text[0]], Labeled[[image], Text[1]], Labeled[[image], Text[2]], Labeled[[image], Text[4]], Labeled[[image], Text[8]]}
```

---

Thicken a shell in 3D:

```wl
In[1]:=
RegionImage[
	Sphere[], 
	{{-1, 1}, {-1 / 2, 1}, {-1, -1 / 3}}, 
	Method -> {"Thickness" -> 4}
	]

Out[1]= [image]
```

#### RasterSize (2)

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

```wl
In[1]:= RegionImage[Annulus[]]

Out[1]= [image]

In[2]:= ImageDimensions[%]

Out[2]= {360, 360}
```

Specify the raster size:

```wl
In[3]:= RegionImage[Annulus[], RasterSize -> 100]

Out[3]= [image]

In[4]:= ImageDimensions[%]

Out[4]= {100, 100}
```

---

Use ``ImageSize`` to specify the display size:

```wl
In[1]:= RegionImage[Annulus[], ImageSize -> 100]

Out[1]= [image]

In[2]:= ImageDimensions[%]

Out[2]= {360, 360}
```

### Applications (6)

Create the image of a Sierpiński mesh:

```wl
In[1]:= RegionImage[SierpinskiMesh[6]]

Out[1]= [image]
```

---

Rasterization of a 3D knot:

```wl
In[1]:= i = RegionImage[KnotData["Trefoil", "Region"]]

Out[1]= [image]

In[2]:= ListAnimate[Image3DSlices[i]]

Out[2]= DynamicModule[«8»]
```

---

Generate cylindric masks for a volume:

```wl
In[1]:=
vol = ExampleData[{"TestImage3D", "CTengine"}]
dims = ImageDimensions[vol];

Out[1]= [image]

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

Out[2]= [image]

In[3]:= ImageMultiply[vol, mask]

Out[3]= [image]
```

---

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

```wl
In[1]:= everest = GeoElevationData[Entity["Mountain", "MountEverest"], Automatic, "Region"]

Out[1]= [image]

In[2]:= RegionImage[everest]

Out[2]= [image]
```

---

Generate the volume of a polyhedron:

```wl
In[1]:= ico = BoundaryMeshRegion@@First[PolyhedronData["Icosahedron"]]

Out[1]= [image]

In[2]:= RegionImage[ico]

Out[2]= [image]
```

---

"Melting" a snowflake region via curvature flow:

```wl
In[1]:= flake = RegionImage[[image]]

Out[1]= [image]

In[2]:= corn = CurvatureFlowFilter[flake, 16]

Out[2]= [image]

In[3]:= ImageMesh[corn]

Out[3]= [image]
```

### Possible Issues (2)

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

```wl
In[1]:= RegionImage[Circle[], Method -> {"Thickness" -> 0}]

Out[1]= [image]
```

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

```wl
In[2]:= RegionImage[Circle[], Method -> {"Thickness" -> 1}]

Out[2]= [image]
```

---

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

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

Out[1]= [image]
```

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

```wl
In[2]:= vol2 = Image3D[vol, ColorFunction -> (GrayLevel[1, #]&), Background -> Black]

Out[2]= [image]
```

Antialiasing using blur:

```wl
In[3]:= Blur[vol2]

Out[3]= [image]
```

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

```wl
In[4]:= Blur[vol]

Out[4]= [image]
```

### Neat Examples (2)

Estimate the area content of a rasterized disk:

```wl
In[1]:=
img = RegionImage[
	BoundaryDiscretizeRegion[Disk[], PrecisionGoal -> 8], {{-1.2, 1.2}, {-1.2, 1.2}}, 
	RasterSize -> 32
	]

Out[1]= [image]

In[2]:= pixelSize = 2.4 / 32;
```

Compare the area estimate with the disk area π:

```wl
In[3]:= area = ImageMeasurements[img, "Total"] pixelSize^2

Out[3]= 3.13862

In[4]:= area / π

Out[4]= 0.999054
```

---

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

```wl
In[1]:= mesh = BoundaryDiscretizeRegion[Disk[]]

Out[1]= [image]

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

Out[2]= [image]
```

Show the evaluation:

```wl
In[3]:=
NestList[
	ImageMesh[
	RegionImage[#, {{-1, 1}, {-1, 1}}], 
	DataRange -> {{-1, 1}, {-1, 1}}
	]&, 
	mesh, 
	100
	][[1 ;; -1 ;; 25]]

Out[3]= {[image], [image], [image], [image], [image]}
```

## See Also

* [`DiscretizeRegion`](https://reference.wolfram.com/language/ref/DiscretizeRegion.en.md)
* [`DiscretizeGraphics`](https://reference.wolfram.com/language/ref/DiscretizeGraphics.en.md)
* [`Rasterize`](https://reference.wolfram.com/language/ref/Rasterize.en.md)
* [`ImageMesh`](https://reference.wolfram.com/language/ref/ImageMesh.en.md)
* [`MeshRegion`](https://reference.wolfram.com/language/ref/MeshRegion.en.md)

## Related Guides

* [Creating & Importing Images](https://reference.wolfram.com/language/guide/CreatingAndImportingImages.en.md)
* [Image Computation: Update History](https://reference.wolfram.com/language/guide/ImageComputation-UpdateHistory.en.md)

## History

* [Introduced in 2017 (11.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn112.en.md)