卷积与卷积核

By Victor Powell

卷积核是一个小矩阵,用于应用像你在Photoshop或Gimp中可能发现的效果,如模糊、锐化、勾勒或压印。它们也被用于机器学习的'特征提取',一种确定图像最重要部分的技术。在这种情况下,这个过程被更普遍地称为 "卷积"。 (see: 卷积神经网络.)

为了了解它们是如何工作的,让我们从检查一张黑白图像开始。左边的矩阵包含数字,介于0和255之间,每个数字对应于冰墩墩图片中一个像素的亮度。 图片的每个像素已经被放大,以使其更容易看到;最后一张图片是"真实"尺寸。

让我们使用3X3的 {{selectedKernel}} 卷积核来对以上图形进行处理

下面,对于左边图像中的每个3x3的像素块,我们用每个像素乘以内核的相应条目,然后取其总和。这个总和在右边的图像中成为一个新的像素。将鼠标悬停在任何一幅图像的一个像素上,可以看到其数值是如何计算的。

这个过程的一个微妙之处在于如何沿着图像的边缘进行处理。例如,输入图像的左上角只有三个相邻的像素。解决这个问题的一个方法是,在保持新图像大小不变的情况下,将原始图像的边缘值向外扩展一圈。在这个演示中,我们把这些值变成了黑色,从而忽略了这些值。

这里是一个可以自由定义的区域,你可以选择不同的卷积核矩阵,看看它们如何影响原始图像或建立你自己的卷积核。如果浏览器支持,你也可以上传你自己的图像。

The sharpen kernel emphasizes differences in adjacent pixel values. This makes the image look more vivid.

The blur kernel de-emphasizes differences in adjacent pixel values.

The emboss kernel (similar to the sobel kernel and sometimes referred to mean the same) givens the illusion of depth by emphasizing the differences of pixels in a given direction. In this case, in a direction along a line from the top left to the bottom right.

The indentity kernel leaves the image unchanged. How boring!

The custom kernel is whatever you make it.

sobel kernels are used to show only the differences in adjacent pixel values in a particular direction.

An outline kernel (also called an "edge" kernel) is used to highlight large differences in pixel values. A pixel next to neighbor pixels with close to the same intensity will appear black in the new image while one next to neighbor pixels that differ strongly will appear white.