A filter that convolves an image with a given kernel of odd width and height.
- iOS 9.0+
- macOS 10.13+
- Mac Catalyst 13.0+
- tvOS 9.0+
- Metal Performance Shaders
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=6. There are similar savings for addition. For large filters, the savings can be profound.