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

# MPSImageConvolution

A filter that convolves an image with a given kernel of odd width and height.

```
class MPSImageConvolution
```

## Overview

Filter width and height can be either 3, 5, 7 or 9. If there are multiple channels in the source image, each channel is processed independently.

A *separable* convolution filter may perform better when done in two passes. . A convolution filter is separable if the ratio of filter values between all rows is constant over the whole row. For example, this edge detection filter:

![](images/com.apple.metalperformanceshaders/media-2556905@2x.png)

Can instead be separated into the product of two vectors, like so:

![](images/com.apple.metalperformanceshaders/media-2556912@2x.png)

And consequently can be done as two, one-dimensional convolution passes back to back on the same image. In this way, the number of multiplies (ignoring the fact that we could skip zeros here) is reduced from `3*3=9` to `3+3=6`. There are similar savings for addition. For large filters, the savings can be profound.

## Topics

### Initializers

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

### Methods

[`-  initWithDevice:kernelWidth:kernelHeight:weights:`](/documentation/MetalPerformanceShaders/MPSImageConvolution/init(device:kernelWidth:kernelHeight:weights:))

Initializes a convolution filter.

### Properties

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

The height of the filter window. Must be an odd number.

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

The width of the filter window. Must be an odd number.

[`bias`](/documentation/MetalPerformanceShaders/MPSImageConvolution/bias)

The value added to a convolved pixel before it is converted back to its intended storage format.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

### Inherits From

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

---

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)