Live data from Hacker News

Fighting JPEG color banding

uploadcare.com

31–40 of 53 posts

Re: Fighting JPEG color banding

#31

Thing I'd love to try if I had time - a compressor which derives the best table for the image. I'm imagining a loop of: start with the default, compress, calculate the difference from the original, dct the error to see which patterns are missed, adjust the table, repeat. Stop on some given error/size-increase ratio. (yes, I'm trying to get someone else nerd sniped into doing this) Edit: something like this https://ww…

Guetzli was already mentioned and roughly does what you are talking about.

MozJPEG [1] includes several quantization tables that are optimized for different contexts (see the quant-table flag and source code for specific tables[2]), and the default quantization table has been optimized to outperform the recommended quantization tables in the original JPEG spec (Annex K).

It's also worth noting that MozJPEG uses Trellis quantization [3] to help improve quality without a per-image quantization table search. Basically rather than determining an optimal quantization table for the image, it minimizes rate distortion on a per-block level by tuning the quantized coefficients.

Both the SSIM and PSNR tuned quantization tables (2 and 4) provided by MozJPEG use a lower value in the first position of the quantization just like this article suggests (9 and 12 vs the libjpeg default of 16).

[1] https://github.com/mozilla/mozjpeg

[2] https://github.com/mozilla/mozjpeg/blob/5c6a0f0971edf1ed3cf3...

[3] https://en.wikipedia.org/wiki/Trellis_quantization

Re: Fighting JPEG color banding

#32

Thing I'd love to try if I had time - a compressor which derives the best table for the image. I'm imagining a loop of: start with the default, compress, calculate the difference from the original, dct the error to see which patterns are missed, adjust the table, repeat. Stop on some given error/size-increase ratio. (yes, I'm trying to get someone else nerd sniped into doing this) Edit: something like this https://ww…

Guetzli was already mentioned and roughly does what you are talking about. MozJPEG [1] includes several quantization tables that are optimized for different contexts (see the quant-table flag and source code for specific tables[2]), and the default quantization table has been optimized to outperform the recommended quantization tables in the original JPEG spec (Annex K). It's also worth noting that MozJPEG uses Trell…

> MozJPEG use a lower value in the first position of the quantization just like this article suggests

It has lower value in the first position of the base table, i.e. the table which is used for q=50. With lower qualities this value scales up. This delays color banding from q=50 to roughly say q=40, after that the same effect is appears.

Re: Fighting JPEG color banding

#33
post #2

just use PNG. JPEG sucks.

Well, if we're talking about web, then I it's better to use WebP rather than PNG. It's widely supported by vendors if you do not need to deal with IE: https://caniuse.com/?search=webp .

Do note that if you need to target macOS 10 + Safari, WebP is not available.

WebP is available for macOS 11, even with overlapping versions of Safari, but Apple relies on the OS image library to render some images and they haven't backported WebP supported when they updated Safari.

Re: Fighting JPEG color banding

#34

I love this and would have dearly needed it like 5 years ago. Now, it is still a very interesting read. But given what we have already seen from Nvidia on video compression [0], I think within the next few years, we will move everything to machine-learning-'compressed' images (aka transmitting a super-low-res seed image and some additional ASCII and having an ML model reconstruct and upscale it at the client side). […

Most images are still JPEG (3 decades old) or PNG (2.5 decades old). Countless better formats have been developed, but with the exception of WEBP we are still using the same image formats that existed during the dot-com bubble. Ubiquity trumps improvements in image size.

Better encoders for JPEG or PNG are the main avenues how you can achieve improvements without compatibility problems, and I think that will stay true for another decade, if not more.

Re: Fighting JPEG color banding

#35
This is OK for icon sized images, but it hurts me when I read webpages that incorporate photographs or visualizations in low resolution. They keep saying “Web resolution” and talk about something like 200x200 images maximum.

Even for the past 20 years, when I read webpages with images, I inspect them closely. Often it’s something like a newspaper article with photographs or Wikipedia. I specifically set my Wikipedia settings to deliver me images at the highest possible resolution and now I can actually enjoy reading it. Specifically I use the Timeless skin and set the thumbnail size to the maximum.

Sometimes I come across webpages that describe something like historic trains and all they have are icon sized photographs of them. It’s so sad.

Re: Fighting JPEG color banding

#36
Though its impact may be limited, this is some nice work!

Now could someone look at how video codecs can produce excellent high-detail scenes and motion in 4k resolution while at the same time making a blocky mess out of soft gradients, especially in dark scenes with slow movement?

Re: Fighting JPEG color banding

#37

How is this different from say, what https://kraken.io is doing. When I upload images there I get a smaller file size and the image looks no different

The difference is that the kraken 'about technology' website [0] gives no useful information as to how they are doing it (I guess it's 'proprietary information'), while this article gives a very detailed description of how to compress jpegs. In other words: end users use kraken, developers read this article. [0] https://kraken.io/about/technology

I can take a guess at that "proprietary information". Most image optimization sites are just thin wrappers over something like mozjpeg/zopflipng/etc. 1% tech, 99% marketing

Re: Fighting JPEG color banding

#38

Thing I'd love to try if I had time - a compressor which derives the best table for the image. I'm imagining a loop of: start with the default, compress, calculate the difference from the original, dct the error to see which patterns are missed, adjust the table, repeat. Stop on some given error/size-increase ratio. (yes, I'm trying to get someone else nerd sniped into doing this) Edit: something like this https://ww…

Turns out there is a project which does that: https://github.com/google/guetzli

Guetzli is really hamstrung by its resource usage. When it first hit the news I tried it out, and compressing a full quality JPEG from my phone could take 20-30 minutes on an i7.

Re: Fighting JPEG color banding

#39

I love this and would have dearly needed it like 5 years ago. Now, it is still a very interesting read. But given what we have already seen from Nvidia on video compression [0], I think within the next few years, we will move everything to machine-learning-'compressed' images (aka transmitting a super-low-res seed image and some additional ASCII and having an ML model reconstruct and upscale it at the client side). […

honestly, this scares this shit out of me.

lossy compression is one thing, but to just say that an ML model suggests making pixels like this vs a mathematical formula is totally different things.

Re: Fighting JPEG color banding

#40
post #38

Earlier quoted context omitted.

Turns out there is a project which does that: https://github.com/google/guetzli

Guetzli is really hamstrung by its resource usage. When it first hit the news I tried it out, and compressing a full quality JPEG from my phone could take 20-30 minutes on an i7.

Yeah, I deal with it like an interesting research project, not a tool. For that, it’s MozJPEG.
Post reply on HN