# Accuracy and performance between a division and subtraction for a ratio in decibels

For comparing two images, one can use the Peak Signal-to-Noise Ratio (PSNR) metric, defined as follows:

$$\mathrm{PSNR} = 10 \cdot \log_{10}\left(\frac{\mathrm{MAX}^2}{\mathrm{MSE}}\right) = 20 \cdot \log_{10}(\mathrm{MAX}) - 10 \cdot \log_{10}(\mathrm{MSE})\ dB.$$

with $$\mathrm{MAX}$$ being the maximum gray-scale value ($$2^8-1 = 255$$ in my case), and $$\mathrm{MSE}$$ being the mean squared error.

My question is, among the definition with division ($$\mathrm{PSNR}_{\div}$$) and subtraction ($$\mathrm{PSNR}_{-}$$), which one is the most numerically accurate? And which one is the most computationally efficient?

I made an experiment with MATLAB R2015a, and for some MSE values, I have different scores. For instance, knowing that the machine epsilon is $$\epsilon = 2.2204e{-16}$$, for $$\mathrm{MSE} = 1708.25$$ and $$\mathrm{MSE} = 1710.00$$, I have $$\left| \mathrm{PSNR}_{\div} - \mathrm{PSNR}_{-} \right| = 1.42109e-14$$ and $$7.10543e-15$$ respectively. What can I conclude?

Note: in $$\mathrm{PSNR}_{-}$$, $$20 \cdot \log_{10}(\mathrm{MAX})$$ can be reduced to a pre-computed constant.

• One aspect of your question is numerical analysis, which should be on-topic here. As for what is more efficient on particular hardware, this seems off-topic; also, the simple answer is what you've already done – time both options. – Yuval Filmus Dec 13 '18 at 22:14
• I am interested in answers, ranging from the mathematical to hardware aspects. If the numerical analysis is on-topic, it is a good start! However, I do not understand why floating-point instructions are off-topic? It is not always easy to choose the appropriate StackExchange network for such complex questions. But I am not sure that the mathematical aspects can be separated to the hardware ones for a precise answer. – benlaug Dec 13 '18 at 22:19
• Answers pertaining to particular architectures are typically off-topic here. – Yuval Filmus Dec 13 '18 at 22:21
• Ok, I just edited my question. – benlaug Dec 13 '18 at 22:22
• Note that I did not monitored the time for both options. I actually checked the absolute difference between the numerical results given by both options. – benlaug Dec 13 '18 at 22:25