LLNL / zfp

Compressed numerical arrays that support high-speed random access
http://zfp.llnl.gov
BSD 3-Clause "New" or "Revised" License
754 stars 152 forks source link

Is psnr formula error in ZFP? #207

Closed BingluCS closed 1 year ago

BingluCS commented 1 year ago

In the function "printerror" of the file "utils/zfp.c", the $psnr$ code is "psnr = 20 log10((fmax - fmin) / (2 erms))". The right formula seemly is the $10log{10}((fmax-fmin)^2 \div mse)$. If the code use the $rmse$ to compute the $psnr$, the right code should be "psnr = 20 * log10((fmax - fmin) / (erms))". The $rmse$ is simply equal to $\sqrt{mse}$. This error has an impact on the comparison with other compressors.

lindstro commented 1 year ago

There are several definitions of PSNR in the literature. Some use fmax only, some use fmax - fmin, and some use (fmax - fmin) / 2.

zfp uses the convention that the peak signal is computed in a translation-invariant manner by first centering it on the mid-range (fmin + fmax) / 2, such that peak negative and positive values are the same (in magnitude). The peak signal is then the maximum value, or amplitude, of this normalized signal.

For SNR, you replace peak signal with standard deviation as measure statistical dispersion, which is the L2 norm of the signal after subtracting the mean (this centering on the mean minimizes the L2 norm). For PSNR, the L norm is used instead, and to minimize that you subtract the mid-range (fmin + fmax) / 2. The resulting norm, i.e., peak signal, is (fmax - fmin) / 2.

BingluCS commented 1 year ago

Thanks for your answer. I found that the $psnr$ calculation formulas in sz and zfp are different, the psnr calculated using the formula in sz will be $10log_{10}4$ higher than zfp.