<!--
{
  "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/MPSImageDilate",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSImageDilate"
  },
  "title" : "MPSImageDilate"
}
-->

# MPSImageDilate

A filter that finds the maximum pixel value in a rectangular region by applying a dilation function.

```
class MPSImageDilate
```

## Overview

An [`MPSImageDilate`](/documentation/MetalPerformanceShaders/MPSImageDilate) filter behaves like the [`MPSImageAreaMax`](/documentation/MetalPerformanceShaders/MPSImageAreaMax) filter, except 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
    }
```

A filter that contains all zeros is identical to an [`MPSImageAreaMax`](/documentation/MetalPerformanceShaders/MPSImageAreaMax) filter. Metal handles the center filter element as `0` to avoid causing a general darkening of the image, and it handles the [`edgeMode`](/documentation/MetalPerformanceShaders/MPSUnaryImageKernel/edgeMode) property  as [`MPSImageEdgeMode.clamp`](/documentation/MetalPerformanceShaders/MPSImageEdgeMode/clamp) for this filter.

## Topics

### Initializers

[`-  initWithCoder:device:`](/documentation/MetalPerformanceShaders/MPSImageDilate/init(coder:device:))

### Methods

[`-  initWithDevice:kernelWidth:kernelHeight:values:`](/documentation/MetalPerformanceShaders/MPSImageDilate/init(device:kernelWidth:kernelHeight:values:))

Initializes the kernel with a specified width, height, and weight values.

### Properties

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

The height of the filter window. which must be an odd number.

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

The width of the filter window which must be an odd number.

## Relationships

### Inherits From

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

### Conforms To

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

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

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

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

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

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

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

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

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

### Inherited By

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

---

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)