convolutionRGB3X3()
Applies a convolution 3 x 3 filter to the RGB components of an image.
Declaration
class func convolutionRGB3X3() -> any CIFilter & CIConvolutionReturn Value
The convolved image.
Discussion
This method applies a 3 x 3 convolution to the RGB 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. This filter differs from the convolution3X3() filter, which processes all of the color components including the alpha component.
The convolution-RGB 3 x 3 filter uses the following properties:
biasA
floatrepresenting the value that’s added to each output pixel.weightsA CIVector representing the convolution kernel.
inputImageA CIImage containing the image to process.
The following code creates a filter that sharpens the input image:
func convolutionRGB3X3(inputImage: CIImage) -> CIImage {
let convolutionFilter = CIFilter.convolutionRGB3X3()
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]