Contents

convolution9Horizontal()

Applies a convolution-9 horizontal filter to the RGBA components of an image.

Declaration

class func convolution9Horizontal() -> any CIFilter & CIConvolution

Return Value

The modified image.

Discussion

This method applies a 9 x 1 convolution to the RGBA components of an image. The effect uses a 9 x 1 area surrounding an input pixel, the pixel itself, and those within a distance of 4 pixels horizontally. The effect repeats this for every pixel within the image. Unlike the convolution filters, which use square matrices, this filter can only produce effects along a horizontal axis. You can combine this filter with the convolution9Vertical() to apply separable 9 x 9 convolutions.

The convolution 9-horizontal 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 detects edges in the input image:

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

[Image]

See Also

Filters