5D Library › 计算美学、视觉显著性图谱与人机界面认知工程 · English

第五章 看得清:空间频率通道、对比敏感度与 WCAG

一个元素要被注意到,首先要被看见;一段文字要被读懂,首先要看得清。本章从视觉系统怎样按空间频率分解图像讲起,到对比敏感度函数,再到网页无障碍标准中的相对亮度与对比度公式。第 34 本已经讨论过韦伯定律与心理物理学的测量方法,这里只在需要时回顾。

空间频率通道

坎贝尔与罗布森 1968 年把傅里叶分析用于光栅的可见性 (Campbell and Robson 1968)。他们测量了正弦光栅与方波、矩形波等复杂光栅的对比度阈值,发现复杂光栅的阈值可以由其傅里叶分量的阈值预测:例如方波在其基频分量的振幅达到同频率正弦光栅的阈值时被看见;只有当它的三次谐波也达到阈值时,方波才在外观上与正弦光栅区分开来。他们据此提出,视觉系统包含若干相互独立的「通道」,每个通道只对一个较窄的空间频率范围敏感。

用一个方波的傅里叶级数就能写出这个推理:对比度为 cc 的方波,其基频分量的振幅为 4c/π4c/\pi,三次谐波为 4c/(3π)4c/(3\pi)。若各通道独立检测,则方波的检测阈值是正弦阈值的 π/4\pi/4 倍,而「看起来是方的」需要三次谐波在频率 3f3f 处达到阈值。

对比敏感度函数

把正弦光栅的阈值对比度的倒数对空间频率作图,就是对比敏感度函数(CSF)。人眼的 CSF 是带通的:在中等空间频率(每度几周)最敏感,低频与高频都较差。图像压缩中常用的一个解析近似是曼诺斯与萨克里森 1974 年给出的公式 (Mannos and Sakrison 1974)

A(f)=2.6(0.0192+0.114f)e−(0.114f)1.1,A(f) = 2.6\,(0.0192 + 0.114f)\,e^{-(0.114f)^{1.1}},

其中 ff 的单位是周/度。下面的程序 A 部分求出它的峰值;B 部分用坎贝尔—罗布森的逻辑计算方波的两个阈值(假设峰值处的正弦阈值为 0.5%,这是一个示意值);C 部分把屏幕上的文字换算成视角与空间频率。所罗门与佩利 1994 年发现字母识别依赖一个约每字母 3 周的空间频率带 (Solomon and Pelli 1994);莱格与比格洛 2011 年的综述给出正常视力读者的「临界字号」约为 x 高 0.2 度,阅读速度在 x 高 0.2 到 2 度之间(约十倍的范围)保持最高,他们称之为「流畅范围」(Legge and Bigelow 2011)。

推导

# Spatial-frequency channels and the contrast sensitivity function (CSF).
# A: Mannos & Sakrison (1974) CSF, A(f) = 2.6 (0.0192 + 0.114 f) exp(-(0.114 f)^1.1),
#    f in cycles/degree, normalised to a peak of 1; peak frequency found numerically.
# B: Campbell & Robson (1968) logic: a square wave of contrast c has a fundamental of
#    amplitude 4c/pi and a third harmonic 4c/(3 pi). If each channel detects its own
#    frequency independently, the square wave is seen when its fundamental reaches the
#    sine threshold (ratio pi/4), and looks different from a sine wave once the third
#    harmonic reaches threshold at 3f. Absolute threshold: assumed 0.5 % at the peak.
# C: text as a stimulus: letters are identified through a band of about 3 cycles per
#    letter (Solomon & Pelli 1994); x-height compared with the critical print size of
#    about 0.2 deg (Legge & Bigelow 2011). Pixel = 1/96 inch (the CSS reference pixel
#    subtends about 0.0213 deg at 28 inches).
import math

def csf(f):
    return 2.6 * (0.0192 + 0.114 * f) * math.exp(-(0.114 * f) ** 1.1)

PEAK = max((csf(k / 1000), k / 1000) for k in range(1, 60001))
def S(f): return csf(f) / PEAK[0]                  # normalised sensitivity
T0 = 0.005                                         # assumed threshold contrast at peak

if __name__ == "__main__":
    print(f"A. CSF peak at {PEAK[1]:.2f} c/deg (raw value {PEAK[0]:.3f})")
    print("   f (c/deg)        0.5     1     2     4     8    16    32    48")
    print("   sensitivity  " + "".join(f"{S(f):6.2f}"
                                     for f in (.5, 1, 2, 4, 8, 16, 32, 48)))
    hi = next(k / 10 for k in range(int(PEAK[1] * 10), 2000) if S(k / 10) < T0)
    print(f"   threshold contrast passes 100 % (invisible) at about {hi:.0f} c/deg")
    print("B. square-wave grating, contrast thresholds (assumed 0.5 % at the peak)")
    print("   f      sine   square: seen  looks square")
    for f in (0.5, 1, 2, 4, 8, 12):
        ts = T0 / S(f)
        print(f"   {f:4.1f} {ts:7.3%} {ts * math.pi / 4:12.3%}"
              f" {T0 / S(3 * f) * 3 * math.pi / 4:12.3%}")
    print("C. text at 1/96-inch pixels (x-height 0.5 em; 3 cycles per letter height)")
    print("   distance  font  x-height  vs 0.2 deg critical size  letter band c/deg")
    for dist in (71.12, 50.0):                     # 28 in = CSS reference distance
        px = math.degrees(2.54 / 96 / dist)        # small-angle pixel size, degrees
        for size in (12, 16, 24):
            xh = 0.5 * size * px; band = 3 / (2 * xh)    # letter height ~ 2 x-heights
            print(f"   {dist:5.1f} cm {size:4d} px {xh:7.3f} deg {xh / 0.2:16.2f} x"
                  f" {band:16.1f}  S = {S(band):.2f}")
# A. CSF peak at 7.89 c/deg (raw value 0.981)
#    f (c/deg)        0.5     1     2     4     8    16    32    48
#    sensitivity    0.19  0.32  0.54  0.83  1.00  0.70  0.15  0.02
#    threshold contrast passes 100 % (invisible) at about 59 c/deg
# B. square-wave grating, contrast thresholds (assumed 0.5 % at the peak)
#    f      sine   square: seen  looks square
#     0.5  2.584%       2.029%       2.697%
#     1.0  1.552%       1.219%       1.673%
#     2.0  0.929%       0.730%       1.221%
#     4.0  0.605%       0.475%       1.314%
#     8.0  0.500%       0.393%       3.324%
#    12.0  0.558%       0.438%      12.168%
# C. text at 1/96-inch pixels (x-height 0.5 em; 3 cycles per letter height)
#    distance  font  x-height  vs 0.2 deg critical size  letter band c/deg
#     71.1 cm   12 px   0.128 deg             0.64 x             11.7  S = 0.91
#     71.1 cm   16 px   0.171 deg             0.85 x              8.8  S = 0.99
#     71.1 cm   24 px   0.256 deg             1.28 x              5.9  S = 0.96
#     50.0 cm   12 px   0.182 deg             0.91 x              8.2  S = 1.00
#     50.0 cm   16 px   0.243 deg             1.21 x              6.2  S = 0.97
#     50.0 cm   24 px   0.364 deg             1.82 x              4.1  S = 0.84

A 部分中,曼诺斯—萨克里森公式的峰值在 7.89 周/度;以峰值为 1,0.5 周/度处的敏感度只有 0.19,32 周/度处为 0.15;在假设的阈值下,约 59 周/度以上的光栅即使对比度为 100% 也看不见。B 部分中,频率 1 周/度时正弦阈值为 1.552%,方波在 1.219% 时就能被看见(比例为 π/4\pi/4),在 1.673% 时才「看起来是方的」;到 12 周/度,三次谐波落在 36 周/度、敏感度很低的区域,方波要到 12.168% 才与正弦波区分开来,即在高频处方波看起来就像正弦波。图 4 左画出了这两条阈值曲线。

C 部分把这些数字用到文字上。CSS 的参考像素定义为在约 28 英寸(71.1 厘米)的距离上张角约 0.0213 度;按此计算,12 像素字(x 高取 0.5 em)的 x 高为 0.128 度,只有临界字号的 0.64 倍;16 像素为 0.171 度(0.85 倍);24 像素为 0.256 度(1.28 倍)。在 50 厘米处,16 像素字的 x 高为 0.243 度,已超过临界字号。以「每字母高度 3 周」估算,这些文字所需的空间频率在 4–12 周/度之间,落在对比敏感度最高的区域附近(敏感度 0.84–1.00)。这说明,常见的正文字号在适当的观看距离下处于人眼最适合的空间频率范围,而 12 像素的小字在桌面显示器的参考距离上会低于临界字号——这一结论取决于观看距离与字体的 x 高比例,后者在不同字体间差别不小。

WCAG 的相对亮度与对比度

网页内容无障碍指南(WCAG)2.x 用一个简单的公式定义文字与背景的对比度 (W3C 2008, 2023)。先把每个 8 位 sRGB 通道值 vv 换成 c=v/255c = v/255,再线性化:

clin={c/12.92,c≤t,(c+0.0551.055)2.4,c>t,c_{\text{lin}} = \begin{cases} c/12.92, & c \le t,\\[2pt] \left(\dfrac{c+0.055}{1.055}\right)^{2.4}, & c > t,\end{cases}

相对亮度 L=0.2126R+0.7152G+0.0722BL = 0.2126R + 0.7152G + 0.0722B(R,G,BR, G, B 为线性化后的值),对比度为 (L1+0.05)/(L2+0.05)(L_1 + 0.05)/(L_2 + 0.05),L1L_1 为较亮者。AA 级要求正文至少 4.5:1、大号文字至少 3:1;AAA 级要求正文至少 7:1、大号文字至少 4.5:1。

阈值 tt 有两个版本。WCAG 2.0 原文写的是 0.03928;sRGB 的国际标准 IEC 61966-2-1 用 0.04045 (IEC 1999)。WCAG 在 2021 年 5 月把定义改为 0.04045,并注明这一改动在指南的语境中没有实际影响 (W3C 2023)。

推导

# WCAG 2.x relative luminance and contrast ratio.
# L = 0.2126 R + 0.7152 G + 0.0722 B on linearised sRGB channels; a channel value
# c = v/255 is linearised as c/12.92 if c <= t, else ((c + 0.055)/1.055)^2.4.
# WCAG 2.0 printed t = 0.03928; IEC 61966-2-1 (and WCAG 2.x since May 2021) uses
# t = 0.04045. Contrast = (L1 + 0.05)/(L2 + 0.05). Thresholds: AA 4.5 (large 3),
# AAA 7 (large 4.5).
def lin(v, t=0.04045, top=255):
    c = v / top
    return c / 12.92 if c <= t else ((c + 0.055) / 1.055) ** 2.4

def lum(rgb, t=0.04045):
    return sum(k * lin(v, t) for k, v in zip((0.2126, 0.7152, 0.0722), rgb))

def ratio(a, b, t=0.04045):
    la, lb = sorted((lum(a, t), lum(b, t)), reverse=True)
    return (la + 0.05) / (lb + 0.05)

def hexrgb(h):
    return tuple(int(h[i:i + 2], 16) for i in (1, 3, 5))

if __name__ == "__main__":
    between = [v for v in range(256) if 0.03928 < v / 255 <= 0.04045]
    print(f"A. 8-bit values between the two thresholds: {between}")
    diffs = [abs(lin(v) - lin(v, 0.03928)) for v in range(256)]
    print(f"   (v = 10 -> {10 / 255:.5f}, v = 11 -> {11 / 255:.5f}); all 256 values"
          f" agree,\n   max difference {max(diffs):.1e}")
    d16 = [abs(lin(v, 0.04045, 65535) - lin(v, 0.03928, 65535)) for v in range(65536)]
    n16 = sum(d > 0 for d in d16)
    print(f"   16-bit channels: {n16} values differ, by at most {max(d16):.1e}"
          f" in linear light")
    print("B. pairs (foreground on background)          ratio   AA  AA-large  AAA")
    for fg, bg, note in (("#000000", "#FFFFFF", "black on white"),
                         ("#767676", "#FFFFFF", "grey 46 % on white"),
                         ("#777777", "#FFFFFF", "one step lighter"),
                         ("#FFFFFF", "#D9261C", "white on red button"),
                         ("#FFFFFF", "#0A66C2", "white on blue button"),
                         ("#FFFFFF", "#FF8C00", "white on orange button"),
                         ("#595959", "#F2F2F2", "dark grey on light grey")):
        r = ratio(hexrgb(fg), hexrgb(bg))
        ok = ["yes" if r >= t else "no" for t in (4.5, 3.0, 7.0)]
        print(f"   {fg} on {bg}  {note:24s} {r:5.2f}:1 {ok[0]:>4s} {ok[1]:>8s}"
              f" {ok[2]:>4s}")
    lo = min(v for v in range(256) if ratio((v, v, v), (0, 0, 0)) >= 4.5)
    hi = max(v for v in range(256) if ratio((v, v, v), (255, 255, 255)) >= 4.5)
    print(f"C. grey text passing AA: on white, values <= {hi} (#{hi:02X}{hi:02X}"
          f"{hi:02X}); on black, >= {lo}")
    mid = max(range(256), key=lambda v: min(ratio((v, v, v), (0, 0, 0)),
                                             ratio((v, v, v), (255, 255, 255))))
    print(f"   best worst-case grey: {mid} (#{mid:02X}{mid:02X}{mid:02X}),"
          f" {ratio((mid,) * 3, (0, 0, 0)):.2f}:1 against black,"
          f" {ratio((mid,) * 3, (255,) * 3):.2f}:1 against white")
# A. 8-bit values between the two thresholds: []
#    (v = 10 -> 0.03922, v = 11 -> 0.04314); all 256 values agree,
#    max difference 0.0e+00
#    16-bit channels: 76 values differ, by at most 7.6e-07 in linear light
# B. pairs (foreground on background)          ratio   AA  AA-large  AAA
#    #000000 on #FFFFFF  black on white           21.00:1  yes      yes  yes
#    #767676 on #FFFFFF  grey 46 % on white        4.54:1  yes      yes   no
#    #777777 on #FFFFFF  one step lighter          4.48:1   no      yes   no
#    #FFFFFF on #D9261C  white on red button       4.95:1  yes      yes   no
#    #FFFFFF on #0A66C2  white on blue button      5.69:1  yes      yes   no
#    #FFFFFF on #FF8C00  white on orange button    2.33:1   no       no   no
#    #595959 on #F2F2F2  dark grey on light grey   6.26:1  yes      yes   no
# C. grey text passing AA: on white, values <= 118 (#767676); on black, >= 117
#    best worst-case grey: 117 (#757575), 4.56:1 against black, 4.61:1 against white

A 部分证明了这一点:两个阈值之间没有任何 8 位整数值——v=10v = 10 时 c=0.03922c = 0.03922,低于两者;v=11v = 11 时 c=0.04314c = 0.04314,高于两者——所以 256 个值的线性化结果完全相同,任何 8 位颜色的对比度也完全相同。只有在 16 位通道上才有 76 个值落在两个阈值之间,差异最大为 7.6×10−77.6\times10^{-7}(线性光),对 4.5:1 之类的判定没有影响。

B 部分列出几组常见配色:#767676 灰字在白底上为 4.54:1,刚好通过 AA;亮一级的 #777777 为 4.48:1,就不通过——标准在阈值处是一条硬线。白字在红色按钮(#D9261C)上为 4.95:1,在蓝色按钮(#0A66C2)上为 5.69:1,都通过 AA;白字在橙色按钮(#FF8C00)上只有 2.33:1,连大号文字的 3:1 都达不到。C 部分显示,在白底上通过 AA 的灰字最亮为 118(#767676),在黑底上最暗为 117;所以只有 117 与 118 两个灰度对黑和对白都通过 AA,117 对黑与对白分别为 4.56:1 与 4.61:1。图 4 右画出了灰度对白与对黑的对比度曲线。

左:在曼诺斯—萨克里森对比敏感度函数与「峰值处阈值 0.5%」的假设下,正弦光栅的阈值对比度(实线)与方波「看起来是方的」所需的对比度(虚线,三次谐波达到阈值);高频处两条曲线分开,方波看起来就像正弦波。右:灰色文字(0–255)在白底与黑底上的 WCAG 对比度;横线自下而上为 3:1、4.5:1 与 7:1。

证据

对比度公式的地位与局限。 WCAG 2.x 的对比度是一个可以审计的工程定义,不是对可读性的完整心理物理模型:它只用「大号文字」一档(18 点以上,或粗体 14 点以上)粗略区分字号与字重,不考虑空间频率(上一节),也不考虑极性(深字浅底与浅字深底在同一对比度下的可读性不同)。为此提出的 APCA(高级感知对比度算法)曾作为探索性内容进入 WCAG 3 工作草案,但已于 2023 年因未获工作组支持而移出;截至 2026 年 4 月的编辑草案仍写明「WCAG 3 使用的对比度算法尚待确定」,WCAG 3 本身距离定稿还有数年 (Roselli 2026)。所以在当前的合规语境中,WCAG 2.x 的 4.5:1 仍是通行的判定标准;APCA 只能视为研究中的替代方案。

假说 · 尚未验证 · 对比度与小字的交互

作者的假说(尚未确立): 在 x 高低于临界字号(约 0.2 度)的小字上,把对比度从 4.5:1 提高到 7:1 带来的阅读速度提升,大于在 x 高 0.3 度以上的正文字号上同样提高对比度带来的提升。什么样的结果能证明它是错的: 在事先登记的阅读速度实验中,「字号 × 对比度」交互作用的置信区间包含零或方向相反。

本章小结

坎贝尔与罗布森的实验支持视觉系统中存在相对独立的空间频率通道:方波在基频达到阈值时被看见,在三次谐波达到阈值时才显得「方」。曼诺斯—萨克里森的对比敏感度函数在约 7.9 周/度处最敏感;常见正文字号的字母识别频带落在这一区域附近,而 12 像素小字在桌面参考距离上低于约 0.2 度的临界字号。WCAG 的相对亮度与对比度公式照写;0.03928 与 0.04045 两个阈值在 8 位色上给出完全相同的结果,程序逐值证明。APCA 已移出 WCAG 3 草案,WCAG 3 的对比度算法尚未确定。

参考文献

Campbell, F. W., and J. G. Robson. 1968. “Application of Fourier Analysis to the Visibility of Gratings.” Journal of Physiology 197 (3): 551–66.
IEC. 1999. IEC 61966-2-1: Multimedia Systems and Equipment – Colour Measurement and Management – Part 2-1: Colour Management – Default RGB Colour Space – sRGB. International Electrotechnical Commission.
Legge, Gordon E., and Charles A. Bigelow. 2011. “Does Print Size Matter for Reading? A Review of Findings from Vision Science and Typography.” Journal of Vision 11 (5): Article 8, 1–22. https://doi.org/10.1167/11.5.8.
Mannos, James L., and David J. Sakrison. 1974. “The Effects of a Visual Fidelity Criterion on the Encoding of Images.” IEEE Transactions on Information Theory 20 (4): 525–36.
Roselli, Adrian. 2026. WCAG3 Contrast as of April 2026. Blog post, adrianroselli.com.
Solomon, Joshua A., and Denis G. Pelli. 1994. “The Visual Filter Mediating Letter Identification.” Nature 369: 395–97.
W3C. 2008. Web Content Accessibility Guidelines (WCAG) 2.0. W3C Recommendation, 11 December 2008.
W3C. 2023. Web Content Accessibility Guidelines (WCAG) 2.2. W3C Recommendation, 2023; relative-luminance definition with the note on the threshold change of May 2021.

Fan, Y. (2026). Computational Aesthetics, Visual Saliency Maps and Cognitive Ergonomics in User Interface Design: From the Hick–Hyman Law and Spatial Frequency Channels to Saccadic Trajectory Modelling, Read Beside the Kaogongji and Classical Treatise on Architectural Methods [计算美学、视觉显著性图谱与人机界面认知工程] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23836258 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).