Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mozjpeg -quality <=51 introduces artifacts #393

Open
hyperknot opened this issue Mar 1, 2021 · 5 comments
Open

mozjpeg -quality <=51 introduces artifacts #393

hyperknot opened this issue Mar 1, 2021 · 5 comments

Comments

@hyperknot
Copy link

hyperknot commented Mar 1, 2021

On the following image, any quality value under <= 51 introduces bad artifacts. They are not present with libjpeg-turbo on any quality settings.

mozjpeg-bug

I don't think it's working as it should as the size saving from 51 vs 52 is minimal. On the sample image: 76058 vs. 76859 bytes.

q51:
q51

q52:
q52

On a color corrected monitor the black lines are very visible, on my laptop it's barely noticable. But here is how they look with a levels adjustment.

q51
q51levels

q52
q52levels

@kornelski
Copy link
Member

kornelski commented Mar 1, 2021

The horizontal lines are caused by trellis quantization of DC coefficients.

This is sort-of intentional, as it usually helps without introducing visible distortion. This image is just an unfortunate case that makes this compression more visible.

So I can only recommend using higher qualities here, because the algorithm decides the lines are an acceptable flaw for lower-quality images.

A more advanced option, if you need to compress harder, is to set a custom quantization table that compresses DC coefficient less, and AC coefficients more.

@hyperknot
Copy link
Author

And can I be sure that it's not used over q52+? I find this optimisation strange to be honest, it provides almost no benefits to file size and produces visual artifacts which might or might not be visible based on the image, all that for 1.1% of savings.

@kornelski
Copy link
Member

There are 100 quality levels, if each one saves 1% that's pretty good :)

This algorithm is more effective on gradients and visually busy images. Your image is an edge case where it's not beneficial.

The DC trellis option is used for all quality levels, even 99 and 100. It's just that the distortion it causes is more visible in lower quality levels, because these levels preserve color of flat areas less precisely, so a "smallest" change of background color is still big in absolute terms.

I think it should be safe to assume that quality >52 won't cause such distortion unexpectedly. The distortion depends on DC quantization level, and that depends on quality setting and quantization table chosen.

@mattmischuk
Copy link

@hyperknot using mssim-tuned kodak seems to fix your artifacts for similar savings. ~10kb more in this case.

@hyperknot
Copy link
Author

@hyperknot using mssim-tuned kodak seems to fix your artifacts for similar savings. ~10kb more in this case.

But the funny thing is that using q52 barely adds to the file size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants