本文介绍了怎样高斯模糊的图像,而无需使用任何内置高斯函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用本地高斯模糊的公式来模糊自己的形象。我读,但我不知道如何实现这一点。

I want to blur my image using the native Gaussian blur formula. I read this, but I am not sure how to implement this.

我如何用公式来决定权重?

How do I use the formula to decide weights?

[我提到MATLAB,因为我不希望使用任何内置的功能,它具有]

[I mentioned MATLAB because I do not want to use any built in functions that it has]

推荐答案

编写一个天真的高斯模糊其实是pretty容易。它以完全相同的方式与任何其他卷积滤波器完成的。一框和高斯滤波器之间唯一的区别是使用的基质

Writing a naive gaussian blur is actually pretty easy. It is done in exactly the same way as any other convolution filter. The only difference between a box and a gaussian filter is the matrix you use.

假设你有一个形象的定义如下:

Imagine you have an image defined as follows:

 0  1  2  3  4  5  6  7  8  9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99

一个3×3的框滤波器矩阵的定义如下:

A 3x3 box filter matrix is defined as follows:

0.111 0.111 0.111
0.111 0.111 0.111
0.111 0.111 0.111

要应用高斯模糊,你会做到以下几点:

To apply the gaussian blur you would do the following:

有关像素11,您将需要加载像素0,1,2,10,11,12,20,21,22。

For pixel 11 you would need to load pixels 0, 1, 2, 10, 11, 12, 20, 21, 22.

在随后将通过3×3模糊滤波器的左上部分相乘的像素0。像素1由顶部中间,象素2,右上像素3中,像素10通过左中等等。

you would then multiply pixel 0 by the upper left portion of the 3x3 blur filter. Pixel 1 by the top middle, pixel 2, pixel 3 by top right, pixel 10 by middle left and so on.

于是干脆加入他们,并将结果写入像素11.正如你所看到的像素11现在本身的平均值和周围的像素。

Then add them altogether and write the result to pixel 11. As you can see Pixel 11 is now the average of itself and the surrounding pixels.

边缘的情况下做的越来越复杂了一点。你用什么样的价值观的纹理边缘的值?单程可以包裹轮的另一侧。这看起来好了以后平铺图像。另一种方法是对像素推入周围的地方。

Edge cases do get a bit more complex. What values do you use for the values of the edge of the texture? One way can be to wrap round to the other side. This looks good for an image that is later tiled. Another way is to push the pixel into the surrounding places.

因此​​,对于左上方可以按照以下方式放置样本:

So for upper left you might place the samples as follows:

 0  0  1
 0  0  1
10 10 11

我希望你能看到这是如何可以很容易地扩展到较大的滤波器内核(即5×5或9x9的等等)。

I hope you can see how this can easily be extended to large filter kernels (ie 5x5 or 9x9 etc).

高斯滤波器和一个箱式滤波器之间的差别在于去在基质中的数字。高斯滤波器使用跨一个行和列的一个高斯分布。

The difference between a gaussian filter and a box filter is the numbers that go in the matrix. A gaussian filter uses a gaussian distribution across a row and column.

例如对于任意定义(即这不是高斯,但可能并不遥远)的过滤器

e.g for a filter defined arbitrarily as (ie this isn't a gaussian, but probably not far off)

0.1 0.8 0.1

第一列将是相同的,但乘以成以上的行的第一个项目。

the first column would be the same but multiplied into the first item of the row above.

0.01 0.8 0.1
0.08
0.01

第二列将是相同的,但这些值将由0.8以上(等)的行中的成倍增加。

The second column would be the same but the values would be multiplied by the 0.8 in the row above (and so on).

0.01 0.08 0.01
0.08 0.64 0.08
0.01 0.08 0.01

将所有上述共同的的结果应该等于1以上滤波器和原来框滤波器之间的差异将是写入的端的像素将具有朝向中心像素​​重得多的加权(即一个是在该位置的话)。发生模糊,因为周围的像素也模糊成像素,虽然不及。使用这种过滤器你得到一个模糊的,但一个不破坏尽可能多的高频信息(从像素到像素的颜色即快速变化)。

The result of adding all of the above together should equal 1. The difference between the above filter and the original box filter would be that the end pixel written would have a much heavier weighting towards the central pixel (ie the one that is in that position already). The blur occurs because the surrounding pixels do blur into that pixel, though not as much. Using this sort of filter you get a blur but one that doesn't destroy as much of the high frequency (ie rapid changing of colour from pixel to pixel) information.

这些类型的过滤器可以做很多有趣的事情。可以执行使用这种过滤器的通过从当前像素减去周围像素的边缘检测。这将使只是在颜色(高频)背后的变化真大。

These sort of filters can do lots of interesting things. You can do an edge detect using this sort of filter by subtracting the surrounding pixels from the current pixel. This will leave only the really big changes in colour (high frequencies) behind.

编辑:一个5×5滤波器内核是如上定义完全相同

A 5x5 filter kernel is define exactly as above.

如用的过滤器

0.01 0.02 0.04 0.02 0.01
0.02 0.04 0.08 0.04 0.02
0.04 0.08 0.16 0.08 0.04
0.02 0.04 0.08 0.04 0.02
0.01 0.02 0.04 0.02 0.01

采取一些任意的位置,你可以看到那个位置0,0简便0.1 * 0.1。位置0,2是0.1 * 0.4,位置2,图2是0.4 * 0.4和1位,2是0.2 * 0.4

taking some arbitrary positions you can see that position 0, 0 is simple 0.1 * 0.1. Position 0, 2 is 0.1 * 0.4, position 2, 2 is 0.4 * 0.4 and position 1, 2 is 0.2 * 0.4.

我希望给你一个足够好的解释。

I hope that gives you a good enough explanation.

这篇关于怎样高斯模糊的图像,而无需使用任何内置高斯函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:19