How does a custom kernel's scale affect a constant patch?
Kernel divides the weighted sum by scale and adds offset. The sum of coefficients determines the response to a constant patch.
Pixel experiment and interpretation
Nine unit coefficients need a divisor of nine to preserve mean brightness. An unnormalized sum can saturate the output.
from PIL import Image, ImageFilter
im=Image.new('L',(5,5),60)
[im.filter(ImageFilter.Kernel((3,3),[1]*9,scale=s)).getpixel((2,2)) for s in (9,1)]Result [60, 255]
中文
自定义卷积核的 scale 如何影响恒定区域?
Kernel 将加权和除以 scale 再加 offset。对恒定区域,权重总和决定直流响应。
像素实验与适用边界
九个系数全为 1 时要除以 9 才保留平均亮度。漏掉归一化可能让输出饱和。
from PIL import Image, ImageFilter
im=Image.new('L',(5,5),60)
[im.filter(ImageFilter.Kernel((3,3),[1]*9,scale=s)).getpixel((2,2)) for s in (9,1)]结果 [60, 255]