<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSImageErode",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSImageErode"
  },
  "title" : "MPSImageErode"
}
-->

# MPSImageErode

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

```
class MPSImageErode
```

## Overview

An [`MPSImageErode`](/documentation/MetalPerformanceShaders/MPSImageErode) behaves like the [`MPSImageAreaMin`](/documentation/MetalPerformanceShaders/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:

```other
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`](/documentation/MetalPerformanceShaders/MPSImageErode) filter is different from its `vImage` counterpart (`MPSImageErode_filter_value = 1.0f-vImageErode_filter_value.`). This allows [`MPSImageDilate`](/documentation/MetalPerformanceShaders/MPSImageDilate) and [`MPSImageErode`](/documentation/MetalPerformanceShaders/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`](/documentation/MetalPerformanceShaders/MPSImageAreaMin) filter. Metal handles the center filter element as `0` to avoid causing a general lightening of the image, and it handles the [`edgeMode`](/documentation/MetalPerformanceShaders/MPSUnaryImageKernel/edgeMode) property as [`MPSImageEdgeMode.clamp`](/documentation/MetalPerformanceShaders/MPSImageEdgeMode/clamp) for this filter.

## Relationships

### Conforms To

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Equatable`](/documentation/Swift/Equatable)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`MPSImageDilate`](/documentation/MetalPerformanceShaders/MPSImageDilate)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)