# 1.2 边缘检测示例（Edge detection example）

对于CV问题，神经网络由浅层到深层，分别可以检测出图片的边缘特征 、局部特征（例如眼睛、鼻子等）、整体面部轮廓

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

## 图片的边缘检测

最常检测的图片边缘有两类：一是**垂直边缘（vertical edges）**，二是**水平边缘（horizontal edges）**

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

图片的边缘检测可以通过与相应滤波器进行卷积来实现。以垂直边缘检测为例，原始图片尺寸为6x6，滤波器filter尺寸为3x3，卷积后的图片尺寸为4x4，得到结果如下：

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

∗表示卷积操作。python中，卷积用conv\_forward()表示；tensorflow中，卷积用tf.nn.conv2d()表示；keras中，卷积用Conv2D()表示

垂直边缘是一个3×3的区域，左边是明亮的像素，中间的并不需要考虑，右边是深色像素。在这个6×6图像的中间部分，明亮的像素在左边，深色的像素在右边，就被视为一个垂直边缘

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/0c8b5b8441557b671431d515aefa1e8a.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/0c8b5b8441557b671431d515aefa1e8a.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/12-bian-yuan-jian-ce-shi-li-ff08-edge-detection-example.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.
