理解高斯模糊算法并确定结果模糊量(σ) [英] Understand Gaussian blur algorithm and determine resulting blur amount (σ)

查看:412
本文介绍了理解高斯模糊算法并确定结果模糊量(σ)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨社区,



我在Unity中生成具有不同模糊量的模糊图像,但我不知道有多少模糊(以绝对值或在生成Sigmaσ)。


我想确定这种高斯模糊实现产生的确切Sigma值(或模糊量的另一个度量,如果有的话?)。我中途了解高斯模糊的理论背景,但我自己并没有写完整个实现
,所以我很难理解高斯公式在这个实现中是如何应用的,以及我如何精确地生成模糊量σ= xyz。你可以帮帮我吗?

$
以下是相关的C#代码行:

Hi community,

I'm generating blurred images with different blur amounts in Unity but I don't know how much blur (spoken in absolute values or in Sigma σ) is produced.
I would like to determine the exact Sigma values (or another measure for blur amounts if there is any?) this Gaussian blur implementation produces. I halfway understand the theoretical background of the Gaussian blur but I didn't write this whole implementation by myself, so I have a hard time to understand how the Gaussian formula is applied in this implementation and how I can precisely produce a blur amount of σ = xyz. Can you help me with this?

Here are the relevant C# code lines:

// ...
int iterations = 2;   // increase to get more blur
float interpolation = 2f;  // increase to get more blur
int kernel = 4;

var rt2 = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);

for (int i = 0; i < iterations; i++)
	{
		float radius = (float)i * interpolation + interpolation;   // I think this is the crucial line affecting resulting Sigma value (?)
		blurMaterial.SetFloat(Uniforms._Radius, radius);

		Graphics.Blit(source, rt2, blurMaterial, 1 + kernel);
		source.DiscardContents();

		// is it a last iteration? If so, then blit to destination
		if (i == iterations - 1)
		{
			Graphics.Blit(rt2, destination, blurMaterial, 2 + kernel);
		} else {
			Graphics.Blit(rt2, source, blurMaterial, 2 + kernel);
			rt2.DiscardContents();
		}
	}
	RenderTexture.ReleaseTemporary(rt2);
}
// ...


I don't know if it is important for you but I also provide a small (and I think the only relevant) part of the shader (written in HLSL) which uses parameters of the C# script for rendering the blur on the textures.// ...


output_13tap vert13Horizontal (vertexInput IN)
{
    output_13tap OUT;

    OUT.vertex = UnityObjectToClipPos(IN.vertex);

    float2 offset1 = float2(_MainTex_TexelSize.x * _Radius * 1.41176470, 0.0); 
    float2 offset2 = float2(_MainTex_TexelSize.x * _Radius * 3.29411764, 0.0);
    float2 offset3 = float2(_MainTex_TexelSize.x * _Radius * 5.17647058, 0.0);

#if UNITY_VERSION >= 540
    float2 uv = UnityStereoScreenSpaceUVAdjust(IN.uv, _MainTex_ST);
#else
    float2 uv = IN.uv;
#endif

    OUT.texcoord = uv;
    OUT.blurTexcoord[0].xy = uv + offset1;
    OUT.blurTexcoord[0].zw = uv - offset1;
    OUT.blurTexcoord[1].xy = uv + offset2;
    OUT.blurTexcoord[1].zw = uv - offset2;
    OUT.blurTexcoord[2].xy = uv + offset3;
    OUT.blurTexcoord[2].zw = uv - offset3;

    return OUT;
}
// Does the same again with _MainTex_TexelSize.y for vertically blurring the image
// ...




我非常感谢任何帮助。

Cult



I appreciate any kind of help very much.
Cult

推荐答案

Hi Cult,

Hi Cult,

关于高斯模糊,以下主题和文档可以帮助您:

About Gaussian blur, the following thread and document may help you:

guassian smoothoothening formula application

使用C#和GDI进行虚拟对象的图像处理+第2部分 - 卷积滤波器

问候,

Stanly


这篇关于理解高斯模糊算法并确定结果模糊量(σ)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆