<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/cannyEdgeDetector()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)cannyEdgeDetectorFilter"
  },
  "title" : "cannyEdgeDetector()"
}
-->

# cannyEdgeDetector()

Applies the Canny edge-detection algorithm to an image.

```
class func cannyEdgeDetector() -> any CIFilter & CICannyEdgeDetector
```

## Return Value

A [`CIImage`](/documentation/CoreImage/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:

- `inputImage`: The [`CIImage`](/documentation/CoreImage/CIImage) to use as an input for the effect.
- `gaussianSigma`: A `float` specifying the sigma of the Gaussian blur to apply, reducing high-frequency noise. Defaults to `1.6`.
- `perceptual`: A `Boolean` specifying whether to use a perceptual color space to compute the edge thresholds. Defaults to `false`.
- `thresholdLow`: A `float` specifying the threshold for weak edges. Defaults to `0.02`.
- `thresholdHigh`: A `float` specifying the threshold for strong edges. Defaults to `0.05`.
- `hysteresisPasses`: The number of hysteresis passes to apply to promote weak edge pixels. Minimum value is `0`, maximum value is `20`, and defaults to `1`.

The following code applies Canny edge-detection to an image:

```swift
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!
}
```

![Two images arranged horizontally. The left image contains a palm tree against a clear sky. The right image contains the result of running the Canny edge-detection filter. The result image contains the outline of the palm tree.](images/com.apple.coreimage/media-4407284@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)