cannyEdgeDetector()
Applies the Canny edge-detection algorithm to an image.
Declaration
class func cannyEdgeDetector() -> any CIFilter & CICannyEdgeDetectorReturn Value
A CIImage with the detected edges.
Discussion
This filter performs a Canny edge-detection on the input image, producing a black-and-white image with the detected edges. White pixels indicate an edge, and black pixels indicate no edge.
The Canny edge-detection filter uses the following properties:
inputImageThe CIImage to use as an input for the effect.
gaussianSigmaA
floatspecifying the sigma of the Gaussian blur to apply, reducing high-frequency noise. Defaults to1.6.perceptualA
Booleanspecifying whether to use a perceptual color space to compute the edge thresholds. Defaults tofalse.thresholdLowA
floatspecifying the threshold for weak edges. Defaults to0.02.thresholdHighA
floatspecifying the threshold for strong edges. Defaults to0.05.hysteresisPassesThe number of hysteresis passes to apply to promote weak edge pixels. Minimum value is
0, maximum value is20, and defaults to1.
The following code applies Canny edge-detection to an image:
func cannyEdgeDetector(inputImage: CIImage) -> CIImage {
let filter = CIFilter.cannyEdgeDetector()
filter.inputImage = inputImage
filter.gaussianSigma = 5
filter.perceptual = false
filter.thresholdLow = 0.02
filter.thresholdHigh = 0.05
filter.hysteresisPasses = 1
return filter.outputImage!
}[Image]