2010年5月16日星期日

Gaussian Blur

需求: 在看OpenCL的Gaussian Blur例子.
基本概念看http://en.wikipedia.org/wiki/Gaussian_blur,有一个新的概念是linearly separable, 原本是一个有权值组成的方形矩阵来对周围的pixel做加权和,现在分开horizaontal and vertical direction方向各一个pass来先后做,好处是什么?提高performance, 对每一个pixel的求值从width * height个乘法降低到width + height个。
例如对于blur宽度是5的情况, 有以下两个预想求得的table值 (取不同的宽度值就对应不同的两个tables. 至于这些table值是怎么求出来的,standard deviation去什么值, 是不是直接代入坐标算出来的呢?有待考证):
static float const blurOffsets5[] = { -4.37988, -2.43235, -0.486391, 1.45925, 3.40585, 5 };
static float const blurWeights5[] = {0.0953448, 0.200199, 0.275104, 0.24745, 0.145682, 0.0362198 };

那么水平(or 竖直)一个方向的blur结果就是: 
    for (index = 0; index < 5; ++index) {
        pixel += read_imagef(srcImage, 当前坐标 + (float2)(blurOffsets5[index], 0.0f)) * blurWeights5[index];
    }
 左边是原图,右边我做出来后倒是像某种海底的浮游动物。


另一个话题 Guassian distribution,(normal distribution).
一维情况下,这个高斯分布(正态分布)的curve的函数是 P(x)=\frac{1}{\sqrt{2\pi } \sigma  } e^{-(x-\mu )^{2} /2\sigma ^{2} } .这个curve的特点包括the total area under it is equal to one. 为什么需要这个requirement呢? 很可能是因为Guassian函数作为probability distribution functions的一种,而后者有这个要求,那Gaussian函数自然也需要满足. 那个mean \mu 控制是curve的中心值, 而standard deviation控制的是曲线形状的宽度.

那么为什么高斯分布在自然中这么常见呢?甚至说一个学校里面学生的考试成绩也是成高斯分布。Central Limit Theorem 是一种解释. "In its simplest form, the Central Limit Theorem states that a sum of random numbers becomes normally distributed as more and more of the random numbers are added together. It does not require the individual random numbers be from any particular distribution, or even that the random numbers be from the same distribution"[The Scientist and Engineer's Guide to Digital Signal Processing, Steven W. Smith].

没有评论:

发表评论