Sum area Table
Backgroud
Since the value of the sums can get quite large, the table entries require
extended precision. The number of bits of precision needed
per component is:
where \(w\) and \(h\) are the width and height of the input image.
\(P_s\) is the precision required to hold values in the summed-area table, and \(P_i\) is the number of bits of precision of the input. Thus, a 256x256 texture with 8-bit components would require a summed-area table with 24 bits of storage per component.
Another limitation of Crow’s summed-area table technique is that it is only capable of implementing a simple box filter. This is because only the sum of the input pixels is
stored; therefore it is not possible to directly apply a generic filter by weighting the inputs.
Heckbert extend summed-area tables to handle more complex filter functions.
Heckbert made two key observations.
- The first is that a summed-area table can be viewed as the
integralof the
input image - the second that the sample function introduced by Crow was the same as the
derivativeof the box filter function. By taking advantage of those observations and
the following convolution identity:
it is possible to extend summed-area tables to handle higher order filter functions, such as the Bartlett filter, or even a Catmull-Rom spline filter. The process is essentially one of repeated box filtering. Higher order filters approach a Gaussian, and exhibit fewer artifacts.
In general, the precision requirements of Heckbert’s
method can be determined as follows:
where \(w\) and \(h\) are the width and height of the input texture,
\(n\) is the degree of the filter function, \(P_i\) is the input image’s
precision, and \(P_s\) is the required precision of the \(n^th\) -degree
summed-area table.
Generate Sum-area Table
In order to efficiently construct summed-area tables, we bor-
row a technique, called recursive doubling。
使用recursive doubling ,在n个处理单元中需要\(log_2(n)\)steps,每个step处理器单元把自己的累计结果传递给另一个处理单元
recursive doubling
目前为了简化描述,我们假设一个pass只会读取2个texels,后面会介绍一次pass读取多个的情况
下面是伪代码:
t_A = InputImage
n = log2(width)
m = log2(height)
// horizontal phase
for(i = 0; i < n; i = i + 1)
t_B[x,y] = t_A[x,y] + t_A[x + 2^i, y]
swap(t_A, t_B)
// vertical phase
for(i = 0; i < m; i = i + 1)
t_B[x,y] = t_A[x,y] + t_A[x, y + 2^i]
swap(t_A, t_B)
// Texture t_A holds the result
实际应用中可能会一pass读取多个texels,比如读取\(r\)个的伪代码:
t_A = InputImage
n = log_r(width)
m = log_r(height)
// horizontal phase
for(i = 0; i < n; i = i + 1)
t_B[x,y] = t_A[x,y]
+ t_A[x + 1 * r^i, y]
+ t_A[x + 2 * r^i, y]
+ ...
+ t_A[x + r * r^i, y]
swap(t_A, t_B)
// vertical phase similar to horizontal phase
// Texture t_A holds the result
Improving Computational Precision
This section first discusses the source of such precision loss and then presents our approach to mitigating this problem.
Source of Precision Loss
One source of precision loss could come from the GPU’s
floating point implementation.
The summed-area table approach can exhibit significant
noise because certain steps in the algorithm involve computing the difference between two relatively large finite-precision numbers with very close values.
This is especially true for pixels in the upper right portion of the image because the monotonically increasing nature of the summed-area function implies that the table values for that region are all quite high.
大数 + 小数:会丢失小数的精度;大数 - 大数:会严重丢失有效数字(这个更可怕)
示例:\(10^{16} + 1234 - 10^{16}\)
先记住双精度 double 的关键点:
- double 尾数有 52 位二进制,等价大约 15~16 位十进制有效数字
- 浮点数保存形式:\(\boldsymbol{尾数 \times 2^{指数}}\),保存的是有效数字,不是小数点后面多少位
- 两个浮点数做加减,第一步:对阶,把指数对齐,尾数移位
第一步:计算 \(10^{16} + 1234\)
我们要加上 1234:
统一指数形式相加:
也就是:
但是!double 只能存 16 位十进制有效数字:
前面 1.00000000000000 已经占了 14 位,后面的 1234 落在第17、18位,超出尾数存储范围,直接被舍入丢弃。
✅ 所以在 double 里:\(\boldsymbol{10^{16} + 1234 = 10^{16}}\)
加完之后,1234 这个信息直接消失了!
第二步:再减去 \(10^{16}\)
表达式变为:
结果自然是 0。
数学上精确结果明明是 1234,浮点算出来得到 0。
这就是灾难性抵消(Catastrophic Cancellation)。
关联积分图(SAT)
积分图求和公式:
原理相同:两个很大、数值接近的SAT值相减,差值本身很小;浮点尾数不足,有效信息丢失,图像产生噪声。
Our Approach to Improving Precision
Using Signed-Offset Pixel Representation
The first modification is to represent pixel values in the original image as signed floating-point values (e.g., values in the range -0.5 to 0.5), as opposed to the traditional approach that uses unsigned pixel values (from 0.0 to 1.0).
Using Origin-Centered Image Representation
The second modification involves anchoring the origin of the
coordinate system to the center of the image, instead of to the
bottom-left image corner. In effect, this simple modification
reduces in half the maximum values of x and y over which
summed areas are accumulated. As a result, for a given pre-
cision level, images of double the width and height can be
handled
Example Applications
Glossy Environmental Reflections
参考:
posted on 2026-10-22 16:31 Ultraman_X 阅读(3) 评论(0) 收藏 举报
浙公网安备 33010602011771号