且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

高斯模糊和卷积核

更新时间:2023-02-26 20:04:01

基本思想是图像的新像素是由靠近它的像素的加权平均值创建的(想象在像素周围画一个圆圈)。

The basic idea is that the new pixels of the image are created by an weighted average of the pixels close to it (imagine drawing a circle around the pixel).

对于图像中的每个像素,您将围绕像素创建一个小方块。让我们假设您将一个像素旁边的8个邻居(包括对角线,即使这里无关紧要),我们执行加权平均以获得中间像素。

For each pixel in the image you are going to create a little square around the pixel. Lets say you take the 8 neighbors next to a pixel (including diagonals even though do not matter here), and we perform a weighted average to get the middle pixel.

In高斯模糊情况下,它分解为两个一维操作。对于每个像素,仅在行方向上的像素旁边取一些像素。将像素值乘以从高斯分布计算的权重(或者如果您为了视觉效果而不是出于科学原因,权重可以是任何看起来很好的东西),并将它们相加。另一种看待它的方法是像素制作一个矢量,权重制作一个矢量,你正在采用点积。在列方向上重复此过程作为单独的过程。

In the Gaussian blur case it breaks down to two one dimensional operations. For each pixel take the some amount of pixels next to a pixel in the row direction only. Multiply the pixel values time the weights computed from the Gaussian distribution (or if you are doing this for an visual effect and not for a scientific reason, the weights can anything that looks good) and sum them up. Another way to look at it is the pixel make a vector and the weights make a vector and your are taking the dot product. Repeat this process in the column direction as a separate pass.