Measure or calculate blur amount (σ) of Gaussian blur algorithm
Posted: 2018-08-02T07:33:42-07:00
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. Do you know any tool which allows measuring the blur amount of an image when the original image and the blurred version is provided?
However, I would prefer if I could calculate the exact Sigma values my Gaussian blur implementation produces in order to compare absolute blur values between different images. I halfway understand the theoretical background of the Gaussian blur but I didn't write the whole implementation I use by myself, so I have a hard time to understand how the Gaussian formula is applied in this implementation and which Sigma values it produces. Can you help me with this?
I'll provide the relevant code lines which are written in C# for Unity.
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.
I appreciate any kind of help very much.
Cult
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. Do you know any tool which allows measuring the blur amount of an image when the original image and the blurred version is provided?
However, I would prefer if I could calculate the exact Sigma values my Gaussian blur implementation produces in order to compare absolute blur values between different images. I halfway understand the theoretical background of the Gaussian blur but I didn't write the whole implementation I use by myself, so I have a hard time to understand how the Gaussian formula is applied in this implementation and which Sigma values it produces. Can you help me with this?
I'll provide the relevant code lines which are written in C# for Unity.
Code: Select all
// ...
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);
}
// ...
Code: Select all
// ...
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