convolutionRGB7X7()
Applies a convolution 7 x 7 filter to the RGB components of an image.
Declaration
class func convolutionRGB7X7() -> any CIFilter & CIConvolutionReturn Value
The convolved image.
Discussion
This method applies a 7 x 7 convolution to the RGB components image. The effect uses a 7 x 7 area surrounding an input pixel, the pixel itself, and those within a distance of 3 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 convolution7X7() filter, which processes all of the color components including the alpha component.
The convolution-RGB 7 x 7 filter uses the following properties:
inputImageA CIImage containing the image to process.
weightsA CIVector representing the convolution kernel.
biasA
floatrepresenting the value that’s added to each output pixel.
The following code creates a filter that highlights edges in the input image:
func convolutionRGB7X7(inputImage: CIImage) -> CIImage {
let convolutionFilter = CIFilter.convolutionRGB7X7()
convolutionFilter.inputImage = inputImage
let weights: [CGFloat] = [
0, 0, -1, -1, -1, 0, 0,
0, -1, -3, -3, -3, -1, 0,
-1, -3, 0, 7, 0, -3, -1,
-1, -3, 7, 25, 7, -3, -1,
-1, -3, 0, 7, 0, -3, -1,
0, -1, -3, -3, -3, -1, 0,
0, 0, -1, -1, -1, 0, 0
]
let kernel = CIVector(values: weights, count: 49)
convolutionFilter.weights = kernel
convolutionFilter.bias = 0.0
return convolutionFilter.outputImage!
}[Image]