strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.7k stars 298 forks source link

Kodak Performance Test: low PSNR in large bpp #205

Open allanwlz opened 4 years ago

allanwlz commented 4 years ago

Hi guys, is there any one who have tested encoder with kodak test? I have used the example binary file to encode the pictures, and compute the PSNR with respect to different bpp. Curve0 As the result show, the encoder performs well at low bpp. But with bpp increasing, the PSNR couldn't surpass 40. I have tried lossless encoding, but the PSNR is still below 40.

Livemusic0 commented 4 years ago

Hi, AllanWlz!

What CLI params did you use for encoding?

May be you did not read manual for heif-enc? Take a chance to do it: man heif-enc or heif-enc --help

And now you can see CLI params which can unveil 'hidden defaults': -P, --params show all encoder parameters and if to heif-enc --params we see tune, default=ssim, { psnr,ssim,grain,fastdecode }

Did you select tune param to psnr value at least? You did not mention that.

Furthermore: you can also see -p set encoder parameter (NAME=VALUE) x265 params and you are welcome to thousands of tests with tuning of many CLI params of x265 video encoder (not all cause some of them are for video for example for P- and B-frames; our target is I-frames if I remember correctly): https://x265.readthedocs.io/en/default/cli.html

So you said about PSNR value, but you did not mention how you tried to optimise encoding to better PSNR values.

Hope that let you to dive deeper into problem you mentioned.

Livemusic0 commented 4 years ago

What PSNR should be if to try lossless encoding? Infinity?

Why you want to use PSNR? Are you prefer to optimise encoding for some sort of machine vision (PSNR) or for human eye (SSIM)?

May be you can estimate your encodings by SSIM also? May be it will be closer to application instead of some not so representative parameter?

allanwlz commented 4 years ago

heif-enc -p tune=psnr -p preset=veryslow -q quality input.png -o output.heic heif-convert output.heic output.png

The params i use are shown above. When use different quality value, we can get differernt compression rate. The PSNR is calculated on the output.png.

Dose X265 params also matters? I didn't see infomation about that in --h help.

Using lossless encoding, PSNR should be the same as raw image. I didn't test that, but bpg444 can get PSNR value as hight as 57 (as shown in the top figure). So I think HIEF lossless encoding should get at least same level PSNR.

Curve1

MS-SSIM figure. The same issue.

farindk commented 4 years ago

When you are encoding to/from PNG, there is also the color-space conversion RGB <-> YCbCr, which is not lossless. Only if you pass in the image as YCbCr directly to libheif, you can get true lossless.

allanwlz commented 4 years ago

When you are encoding to/from PNG, there is also the color-space conversion RGB <-> YCbCr, which is not lossless. Only if you pass in the image as YCbCr directly to libheif, you can get true lossless.

Yes, I notice that. But I'm not sure how much influence would that make.

How could I convert to YCbCr with PNG format? As far as I know, PNG only support RGB?

farindk commented 4 years ago

PNG is only RGB. libheif supports Y4M as YCbCr format. I added that when I did some PSNR tests myself.

allanwlz commented 4 years ago

PNG is only RGB. libheif supports Y4M as YCbCr format. I added that when I did some PSNR tests myself.

Hi, may I ask the methods that transform PNG to y4m?

I have tried ffmpeg. But got even worse result.

ffmpeg instruction like: ffmpeg -i input.png -pix_fmt yuv444p -vsync 0 -preset placebo -tune psnr input.y4m -y

allanwlz commented 4 years ago

Hi, AllanWlz!

What CLI params did you use for encoding?

May be you did not read manual for heif-enc? Take a chance to do it: man heif-enc or heif-enc --help

And now you can see CLI params which can unveil 'hidden defaults': -P, --params show all encoder parameters and if to heif-enc --params we see tune, default=ssim, { psnr,ssim,grain,fastdecode }

Did you select tune param to psnr value at least? You did not mention that.

Furthermore: you can also see -p set encoder parameter (NAME=VALUE) x265 params and you are welcome to thousands of tests with tuning of many CLI params of x265 video encoder (not all cause some of them are for video for example for P- and B-frames; our target is I-frames if I remember correctly): https://x265.readthedocs.io/en/default/cli.html

So you said about PSNR value, but you did not mention how you tried to optimise encoding to better PSNR values.

Hope that let you to dive deeper into problem you mentioned.

Hi, i used the parameters this :

heif-enc -p tune=psnr -p preset=veryslow -q quality input.png -o output.heic

heif-convert output.heic output.png

Is that correct? What other X265 parameter should I add?