PNG specification states that there are five possible filters,可以为图像的每一行分别选择。首先给出一些一般性建议:
- 索引彩色和
- 真彩色和灰度图像:“五个滤镜中的任何一个都可能证明是最有效的”
- 如果您只能对整个图像使用一个滤镜,则Paeth可能是最好的
Then it suggests the following,听起来好像是在PNG的开发初期就写的,而且不是很具体:
以下简单的启发式方法在早期测试中表现良好:使用所有五个过滤器计算输出扫描线,并选择给出输出绝对值之和最小的过滤器。 (对于此测试,将输出字节视为带符号的差异。)此方法通常胜过任何单个固定滤波器的选择。但是,随着使用PNG的经验越来越多,很有可能会找到更好的启发式方法。
编码器通常如何挑选使用的滤波器?是上述方法中的典型方法还是现代方法?
编辑:
@ Mark-Setchell指向libpng
source code,其中包含从第2416
行开始的长注释:
/* The prediction method we use is to find which method provides the
* smallest value when summing the absolute values of the distances
* from zero,using anything >= 128 as negative numbers. This is known
* as the "minimum sum of absolute differences" heuristic. Other
* heuristics are the "weighted minimum sum of absolute differences"
* (experimental and can in theory improve compression),and the "zlib
* predictive" method (not implemented yet),which does test compressions
* of lines using different filter methods,and then chooses the
* (series of) filter(s) that give minimum compressed data size (VERY
* computationally expensive).
*
* GRR 980525: consider also
*
* (1) minimum sum of absolute differences from running average (i.e.,* keep running sum of non-absolute differences & count of bytes)
* [track dispersion,too? restart average if dispersion too large?]
*
* (1b) minimum sum of absolute differences from sliding average,probably
* with window size <= deflate window (usually 32K)
*
* (2) minimum sum of squared differences from zero or running average
* (i.e.,~ root-mean-square approach)
*/