---
title: "EdgeDetect"
language: "en"
type: "Symbol"
summary: "EdgeDetect[image] finds edges in image and returns the result as a binary image. EdgeDetect[image, r] finds edges at the scale of the specified pixel range r. EdgeDetect[image, r, t] uses a threshold t for selecting image edges."
keywords: 
- image edges
- image boundary
- line detection
- edge detection
- Canny
- Sobel
- Shen
- Castan
- Prewitt
- hysteresis threshold
- contour
- Hough
- Radon
- edge
canonical_url: "https://reference.wolfram.com/language/ref/EdgeDetect.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Feature Detection"
    link: "https://reference.wolfram.com/language/guide/FeatureDetection.en.md"
  - 
    title: "Image Processing & Analysis"
    link: "https://reference.wolfram.com/language/guide/ImageProcessing.en.md"
  - 
    title: "3D Images"
    link: "https://reference.wolfram.com/language/guide/3DImages.en.md"
  - 
    title: "Scientific Data Analysis"
    link: "https://reference.wolfram.com/language/guide/ScientificDataAnalysis.en.md"
  - 
    title: "Computational Photography"
    link: "https://reference.wolfram.com/language/guide/ComputationalPhotography.en.md"
  - 
    title: "Signal Visualization & Analysis"
    link: "https://reference.wolfram.com/language/guide/SignalAnalysis.en.md"
related_functions: 
  - 
    title: "ImageLines"
    link: "https://reference.wolfram.com/language/ref/ImageLines.en.md"
  - 
    title: "GradientFilter"
    link: "https://reference.wolfram.com/language/ref/GradientFilter.en.md"
  - 
    title: "FindImageShapes"
    link: "https://reference.wolfram.com/language/ref/FindImageShapes.en.md"
  - 
    title: "MorphologicalPerimeter"
    link: "https://reference.wolfram.com/language/ref/MorphologicalPerimeter.en.md"
  - 
    title: "MorphologicalBinarize"
    link: "https://reference.wolfram.com/language/ref/MorphologicalBinarize.en.md"
  - 
    title: "CrossingDetect"
    link: "https://reference.wolfram.com/language/ref/CrossingDetect.en.md"
  - 
    title: "CornerFilter"
    link: "https://reference.wolfram.com/language/ref/CornerFilter.en.md"
  - 
    title: "GaussianMatrix"
    link: "https://reference.wolfram.com/language/ref/GaussianMatrix.en.md"
  - 
    title: "ShenCastanMatrix"
    link: "https://reference.wolfram.com/language/ref/ShenCastanMatrix.en.md"
---
# EdgeDetect

EdgeDetect[image] finds edges in image and returns the result as a binary image.

EdgeDetect[image, r] finds edges at the scale of the specified pixel range r.

EdgeDetect[image, r, t] uses a threshold t for selecting image edges.

## Details and Options

* Edges of an image are a set of points between image regions and are typically computed by linking high-gradient pixels. In practice, an edge can have an arbitrary shape.

* ``EdgeDetect`` uses gradient methods to find edges and works with arbitrary 2D and 3D images.

* ``EdgeDetect[image]`` is equivalent to ``EdgeDetect[image, 2]``.

* The following range specifications ``r`` can be used:

|                      |                                                                 |
| -------------------- | --------------------------------------------------------------- |
| r                    | radius r in every dimension (default r = 2)                     |
| {rrow, rcol}         | in 2D, range rrow in height, rcol in width                      |
| {rslice, rrow, rcol} | in 3D, range rslice in height, rrow in depth, and rcol in width |

* ``EdgeDetect[image, r, t]`` uses hysteresis thresholding with a global threshold ``t``. For additional forms of the threshold parameter, see the reference page for ``MorphologicalBinarize``.

* The following options can be specified:

|         |           |                       |
| ------- | --------- | --------------------- |
| Method  | Automatic | edge detection method |
| Padding | "Fixed"   | padding method        |

* Possible settings for ``Method`` include:

|              |                                                        |
| ------------ | ------------------------------------------------------ |
| "Canny"      | first-order directional Gaussian derivatives (default) |
| "ShenCastan" | first-order derivatives of exponentials                |
| "Sobel"      | binomial generalization of Sobel masks                 |

* By default, all straight and curved edges are returned. Selection of edges based on their straightness can be done by setting ``Method -> {"method", "StraightEdges" -> s}``. The default behavior is equivalent to ``"StraightEdges" -> 0``. A setting ``"StraightEdges" -> 1`` selects only the longest and strongest lines.

* ``"StraightEdges"`` is ignored when used with ``Image3D`` objects.

## Examples (8)

### Basic Examples (1)

Detecting edges in a color image:

```wl
In[1]:= EdgeDetect[[image]]

Out[1]= [image]
```

### Scope (4)

Find edges in a color image:

```wl
In[1]:= EdgeDetect[[image]]

Out[1]= [image]
```

---

Specify the scale of edges to detect:

```wl
In[1]:= EdgeDetect[[image], 1]

Out[1]= [image]
```

Specify larger scale to detect coarse features:

```wl
In[2]:= EdgeDetect[[image], 10]

Out[2]= [image]
```

---

Edge selection using an explicit global threshold:

```wl
In[1]:= EdgeDetect[[image], 6, 0.1]

Out[1]= [image]
```

---

Edges of a 3D image:

```wl
In[1]:= i = [image];

In[2]:= Image3D[#, ClipRange -> {{15, 30}, All, {15, 30}}]& /@ {i, EdgeDetect[i]}

Out[2]= {[image], [image]}
```

### Options (2)

#### Method (2)

Shen–Castan edge detection:

```wl
In[1]:= EdgeDetect[[image], 3, Method -> "ShenCastan"]

Out[1]= [image]
```

---

By default, all edges are returned, regardless of their straightness:

```wl
In[1]:=
i = [image];
EdgeDetect[i, 1, .2]

Out[1]= [image]
```

Filter detected edges with their straightness:

```wl
In[2]:= EdgeDetect[i, 1, 0.2, Method -> {"Canny", "StraightEdges" -> 0.4}]

Out[2]= [image]
```

### Properties & Relations (1)

``EdgeDetect`` might return edges that are thicker than one pixel:

```wl
In[1]:= e = EdgeDetect[[image]]

Out[1]= [image]
```

Use ``Thinning`` to get single-pixel-wide edges:

```wl
In[2]:= Thinning[e]

Out[2]= [image]
```

## See Also

* [`ImageLines`](https://reference.wolfram.com/language/ref/ImageLines.en.md)
* [`GradientFilter`](https://reference.wolfram.com/language/ref/GradientFilter.en.md)
* [`FindImageShapes`](https://reference.wolfram.com/language/ref/FindImageShapes.en.md)
* [`MorphologicalPerimeter`](https://reference.wolfram.com/language/ref/MorphologicalPerimeter.en.md)
* [`MorphologicalBinarize`](https://reference.wolfram.com/language/ref/MorphologicalBinarize.en.md)
* [`CrossingDetect`](https://reference.wolfram.com/language/ref/CrossingDetect.en.md)
* [`CornerFilter`](https://reference.wolfram.com/language/ref/CornerFilter.en.md)
* [`GaussianMatrix`](https://reference.wolfram.com/language/ref/GaussianMatrix.en.md)
* [`ShenCastanMatrix`](https://reference.wolfram.com/language/ref/ShenCastanMatrix.en.md)

## Related Guides

* [Feature Detection](https://reference.wolfram.com/language/guide/FeatureDetection.en.md)
* [Image Processing & Analysis](https://reference.wolfram.com/language/guide/ImageProcessing.en.md)
* [3D Images](https://reference.wolfram.com/language/guide/3DImages.en.md)
* [Scientific Data Analysis](https://reference.wolfram.com/language/guide/ScientificDataAnalysis.en.md)
* [Computational Photography](https://reference.wolfram.com/language/guide/ComputationalPhotography.en.md)
* [Signal Visualization & Analysis](https://reference.wolfram.com/language/guide/SignalAnalysis.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Images](https://www.wolfram.com/language/elementary-introduction/10-images.html)
* [An Elementary Introduction to the Wolfram Language: Strings and Text](https://www.wolfram.com/language/elementary-introduction/11-strings-and-text.html)
* [An Elementary Introduction to the Wolfram Language: Ways to Apply Functions](https://www.wolfram.com/language/elementary-introduction/25-ways-to-apply-functions.html)
* [An Elementary Introduction to the Wolfram Language: Applying Functions Repeatedly](https://www.wolfram.com/language/elementary-introduction/27-applying-functions-repeatedly.html)
* [An Elementary Introduction to the Wolfram Language: Creating Websites and Apps](https://www.wolfram.com/language/elementary-introduction/36-creating-websites-and-apps.html)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md) \| [Updated in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md)