Contents

convolution5X5()

Applies a convolution 5 x 5 filter to the RGBA components image.

Declaration

class func convolution5X5() -> any CIFilter & CIConvolution

Return Value

The modified image.

Discussion

This method applies a 5 x 5 convolution to the RGBA components of an image. The effect uses a 5 x 5 area surrounding an input pixel, the pixel itself, and those within a distance of 2 pixels horizontally and vertically. The effect repeats this for every pixel within the image. The work area is then combined with the weight property vector to produce the processed image. This filter differs from the convolutionRGB5X5() filter, which only processes the RGB components.

The convolution 5 x 5 filter uses the following properties:

bias

A float representing the value that’s added to each output pixel as a NSNumber.

weights

A CIVector representing the convolution kernel.

inputImage

An image with the type CIImage.

The following code creates a filter that blurs the input image:

func convolution5X5(inputImage: CIImage) -> CIImage? {
    let convolutionFilter = CIFilter.convolution5X5()
    convolutionFilter.inputImage = inputImage
    let blur: [CGFloat] = [
         1, 1, 1, 1, 1,
         1, 1, 1, 1, 1,
         1, 1, 1, 1, 1,
         1, 1, 1, 1, 1,
         1, 1, 1, 1, 1,
    ].map { $0/25.0 }
    let kernel = CIVector(values: blur, count: 25)
    convolutionFilter.weights = kernel
    convolutionFilter.bias = 0
    return convolutionFilter.outputImage!
}

[Image]

See Also

Filters