Standard image quality metrics, such as PSNR or SSIM, cannot be directly computed on linear high dynamic range colour values because such values non-linearly related to our perception of visible differences. In this work, we develop a new encoding function (PU21) to convert absolute high dynamic range (HDR) linear colour values into approximately perceptually uniform (PU) values, which can be used with standard quality metrics. The proposed PU21 function is based on a recent contrast sensitivity model, fitted to the measurements up to 10 000 cd/m 2 . Unlike the conventional simplified approach of deriving PU functions based on peak sensitivities, we model realistic coding artefacts to find visibility thresholds for our derivation. Furthermore, the new PU accounts for the effect of glare on image quality. The proposed PU21 improves the accuracy of quality predictions for standard metrics of PSNR, VSI, FSIM, SSIM, and MS-SSIM in their correlation with subjective scores on HDR images included in UPIQ, one of the largest HDR image quality datasets.