# 1.3 更多边缘检测内容（More edge detection）

图片边缘有两种渐变方式，一种是由明变暗，另一种是由暗变明。实际应用中，这两种渐变方式并不影响边缘检测结果，可以对输出图片取绝对值操作，得到同样的结果

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/783267536976c27544bbe36ac758a48e.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/783267536976c27544bbe36ac758a48e.png)

> 由亮向暗

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/6a248e5698d1f61ac4ba0238363c4a37.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/6a248e5698d1f61ac4ba0238363c4a37.png)

> 由暗向亮

下图的垂直边缘过滤器是一个3×3的区域，左边相对较亮，右边相对较暗。右图的水平边缘过滤器也是一个3×3的区域，上边相对较亮，而下方相对较暗

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/199323db1d4858ef2463f34323e1d85f.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/199323db1d4858ef2463f34323e1d85f.png)

30（右边矩阵中绿色方框标记元素）代表了左边这块3×3的区域（左边矩阵绿色方框标记部分），这块区域是上边比较亮，下边比较暗，所以它在这里发现了一条正边缘。而-30（右边矩阵中紫色方框标记元素）代表了左边另一块区域（左边矩阵紫色方框标记部分），这块区域是底部比较亮，而上边则比较暗，所以在这里它是一条负边

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/eb8668010205b08fbcbcde7c2bb1fee2.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/eb8668010205b08fbcbcde7c2bb1fee2.png)

10（右边矩阵中黄色方框标记元素）代表的是左边这块区域（左边6×6矩阵中黄色方框标记的部分）。这块区域左边两列是正边，右边一列是负边，正边和负边的值加在一起得到了一个中间值。但假如这是一个非常大的1000×1000大图，就不会出现亮度为10的过渡带了，因为图片尺寸很大，这些中间值就会变得非常小

对于这个3×3的过滤器来说，使用了其中的一种数字组合：

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/20cea5b23b32153fe2a8b8707ef21b6f.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/20cea5b23b32153fe2a8b8707ef21b6f.png)

还可以使用这种：

$$
\begin{bmatrix}1 & 0 & - 1 \ 2 & 0 & - 2 \ 1 & 0 & - 1 \end{bmatrix}
$$

叫做**Sobel**过滤器，优点在于增加了中间一行元素的权重，使得结果的鲁棒性会更高一些

或者：

$$
\begin{bmatrix} 3& 0 & - 3 \ 10 & 0 & - 10 \ 3 & 0 & - 3 \end{bmatrix}
$$

叫做**Scharr过滤器**，也是一种垂直边缘检测，如果将其翻转90度，就能得到对应水平边缘检测

随着深度学习的发展，如果想检测图片的各种边缘特征，而不仅限于垂直边缘和水平边缘，那么filter的数值一般需要通过模型训练得到，将矩阵的所有数字都设置为参数，通过数据反馈，让神经网络自动去学习它们，类似于标准神经网络中的权重$$W$$一样由梯度下降算法反复迭代求得，会发现神经网络可以学习一些低级的特征，例如这些边缘的特征。CNN的主要目的就是计算出这些filter的数值，确定得到了这些filter后，CNN浅层网络也就实现了对图片所有边缘特征的检测

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/f889ad7011738a23d78070e8ed2df04e.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/f889ad7011738a23d78070e8ed2df04e.png)

，


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-si-men-ke-juan-ji-shen-jing-wang-luo-convolutional-neural-networks/convolutional-neural-networks/foundations-of-convolutional-neural-networks/13-geng-duo-bian-yuan-jian-ce-nei-rong-ff08-more-edge-detection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
