Contents

convolution3X3()

Applies a convolution 3 x 3 filter to the RGBA components of an image.

Declaration

class func convolution3X3() -> any CIFilter & CIConvolution

Return Value

The modified image.

Discussion

This method applies a 3 x 3 convolution to the RGBA components of an image. The effect uses a 3 x 3 area surrounding an input pixel, the pixel itself, and those within a distance of 1 pixel 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 convolutionRGB3X3(), which only processes the RGB color components.

The convolution 3 x 3 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 sharpens the input image:

func convolution3X3(inputImage: CIImage) -> CIImage? {
    let convolutionFilter = CIFilter.convolution3X3()
    convolutionFilter.inputImage = inputImage
    let kernel = CIVector(values: [
        0, -2, 0,
        -2, 9, -2,
        0, -2, 0
    ], count: 9)
    convolutionFilter.weights = kernel
    convolutionFilter.bias = 0.0
    return convolutionFilter.outputImage!
}

[Image]

See Also

Filters