---
title: MPSImageConvolution
framework: metalperformanceshaders
role: symbol
role_heading: Class
path: metalperformanceshaders/mpsimageconvolution
---

# MPSImageConvolution

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

## Declaration

```swift
class MPSImageConvolution
```

## Overview

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:

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

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

- [init(coder:device:)](metalperformanceshaders/mpsimageconvolution/init(coder:device:).md)

### Methods

- [init(device:kernelWidth:kernelHeight:weights:)](metalperformanceshaders/mpsimageconvolution/init(device:kernelwidth:kernelheight:weights:).md)

### Properties

- [kernelHeight](metalperformanceshaders/mpsimageconvolution/kernelheight.md)
- [kernelWidth](metalperformanceshaders/mpsimageconvolution/kernelwidth.md)
- [bias](metalperformanceshaders/mpsimageconvolution/bias.md)

## Relationships

### Inherits From

- [MPSUnaryImageKernel](metalperformanceshaders/mpsunaryimagekernel.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

### Convolution Image Filters

- [MPSImageMedian](metalperformanceshaders/mpsimagemedian.md)
- [MPSImageBox](metalperformanceshaders/mpsimagebox.md)
- [MPSImageTent](metalperformanceshaders/mpsimagetent.md)
- [MPSImageGaussianBlur](metalperformanceshaders/mpsimagegaussianblur.md)
- [MPSImageGaussianPyramid](metalperformanceshaders/mpsimagegaussianpyramid.md)
- [MPSImageSobel](metalperformanceshaders/mpsimagesobel.md)
- [MPSImageLaplacian](metalperformanceshaders/mpsimagelaplacian.md)
- [MPSImageLaplacianPyramid](metalperformanceshaders/mpsimagelaplacianpyramid.md)
- [MPSImageLaplacianPyramidAdd](metalperformanceshaders/mpsimagelaplacianpyramidadd.md)
- [MPSImageLaplacianPyramidSubtract](metalperformanceshaders/mpsimagelaplacianpyramidsubtract.md)
- [MPSImagePyramid](metalperformanceshaders/mpsimagepyramid.md)
