---
title: MPSImageErode
framework: metalperformanceshaders
role: symbol
role_heading: Class
path: metalperformanceshaders/mpsimageerode
---

# MPSImageErode

A filter that finds the minimum pixel value in a rectangular region by applying an erosion function.

## Declaration

```swift
class MPSImageErode
```

## Overview

Overview An MPSImageErode behaves like the MPSImageAreaMin filter, except that Metal calculates the intensity at each position relative to a different value before determining which is the maximum pixel value, allowing for shaped, nonrectangular morphological probes. The code example below shows pseudocode for the calculation that returns each pixel value: for each pixel in the filter window     value =  pixel[filterY][filterX] + filter[filterY*filter_width+filterX]     if( value < bestValue ){         result = value         bestValue = value     } The definition of the MPSImageErode filter is different from its vImage counterpart (MPSImageErode_filter_value = 1.0f-vImageErode_filter_value.). This allows MPSImageDilate and MPSImageErode to use the same filter, making open and close operators easier to write. A filter that contains all zeros is identical to an MPSImageAreaMin filter. Metal handles the center filter element as 0 to avoid causing a general lightening of the image, and it handles the edgeMode property as MPSImageEdgeMode.clamp for this filter.

## Relationships

### Inherits From

- [MPSImageDilate](metalperformanceshaders/mpsimagedilate.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Morphological Image Filters

- [MPSImageAreaMax](metalperformanceshaders/mpsimageareamax.md)
- [MPSImageDilate](metalperformanceshaders/mpsimagedilate.md)
- [MPSImageAreaMin](metalperformanceshaders/mpsimageareamin.md)
