cwebp not doing Lossy Alpha Compression

24 views
Skip to first unread message

Alex Lawson

unread,
Jul 26, 2022, 3:18:42 PMJul 26
to WebP Discussion
I'm trying to compress large images to very small filesizes. I found that without an alpha channel, I could compress a 47MB PNG down to a 400KB Webp with q=50. The image looks good. 

With an alpha channel, my 67MB PNG compresses down to 2.7MB image. This is far above the range I expected from not having an alpha channel. This was with alpha_q=80. I tried reducing alpha_q further but the PALETTE was very obvious and the image looked very bad. 

Command Line results are Below.

The alpha compression seems to be lossless from the result (Lossless-alpha compressed size: 2433316 bytes). Is there some flag to turn on lossy alpha compression that I missed? Does cwebp not compress the alpha channel the same way that is compressed the color channels? Is there any way to remediate this, and keep my alpha channel around the same quality as the colors?  Thank you very much for your time. 

cwebp img_rgba.png -q 50 -m 4 -alpha_q 80 -o img_rgba_q=50_alphaq=80_m=4.webp
Saving file  img_rgba_q=50_alphaq=80_m=4  '
File:       img_rgba.png
Dimension: 7360 x 4912 (with alpha)
Output:    2731300 bytes Y-U-V-All-PSNR 44.90 45.87 45.81   45.20 dB
block count:  intra4: 31026
              intra16: 110194  (-> 78.03%)
              skipped block: 39800 (28.18%)
bytes used:  header:            284  (0.0%)
             mode-partition: 113012  (4.1%)
             transparency:   2433317 (58.3 dB)
 Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |       0%|       2%|       8%|      89%|  141220
      quantizer:  |      52 |      52 |      45 |      37 |
   filter level:  |      21 |      63 |      63 |      39 |
Lossless-alpha compressed size: 2433316 bytes
  * Header size: 4335 bytes, image data size: 2428981
  * Lossless features used: PREDICTION
  * Precision Bits: histogram=7 transform=5 cache=0
  * Palette size:   78




James Zern

unread,
Jul 26, 2022, 7:45:45 PMJul 26
to WebP Discussion
Hi Alex,

On Tue, Jul 26, 2022 at 12:18 PM Alex Lawson <amlaw...@gmail.com> wrote:
I'm trying to compress large images to very small filesizes. I found that without an alpha channel, I could compress a 47MB PNG down to a 400KB Webp with q=50. The image looks good. 

With an alpha channel, my 67MB PNG compresses down to 2.7MB image. This is far above the range I expected from not having an alpha channel. This was with alpha_q=80. I tried reducing alpha_q further but the PALETTE was very obvious and the image looked very bad. 

< 70 will be a bit more aggressive. 

Command Line results are Below.

The alpha compression seems to be lossless from the result (Lossless-alpha compressed size: 2433316 bytes). Is there some flag to turn on lossy alpha compression that I missed? Does cwebp not compress the alpha channel the same way that is compressed the color channels? Is there any way to remediate this, and keep my alpha channel around the same quality as the colors?  Thank you very much for your time. 

Alpha is always compressed using the lossless codec [1]. We left uncompressed as an option, but that was mostly an oversight. The loss introduced with -alpha_q is from some pre-filtering.
Lossy compression for RGB uses a separate algorithm (VP8); the alpha is treated independently. With lossless all four channels are compressed as one unit.

 

cwebp img_rgba.png -q 50 -m 4 -alpha_q 80 -o img_rgba_q=50_alphaq=80_m=4.webp
Saving file  img_rgba_q=50_alphaq=80_m=4  '
File:       img_rgba.png
Dimension: 7360 x 4912 (with alpha)
Output:    2731300 bytes Y-U-V-All-PSNR 44.90 45.87 45.81   45.20 dB
block count:  intra4: 31026
              intra16: 110194  (-> 78.03%)
              skipped block: 39800 (28.18%)
bytes used:  header:            284  (0.0%)
             mode-partition: 113012  (4.1%)
             transparency:   2433317 (58.3 dB)
 Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |       0%|       2%|       8%|      89%|  141220
      quantizer:  |      52 |      52 |      45 |      37 |
   filter level:  |      21 |      63 |      63 |      39 |
Lossless-alpha compressed size: 2433316 bytes
  * Header size: 4335 bytes, image data size: 2428981
  * Lossless features used: PREDICTION
  * Precision Bits: histogram=7 transform=5 cache=0
  * Palette size:   78




--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To view this discussion on the web visit https://groups.google.com/a/webmproject.org/d/msgid/webp-discuss/021a0ba6-560d-4687-9c79-cee33f138dddn%40webmproject.org.

Alex Lawson

unread,
Aug 2, 2022, 12:30:40 PMAug 2
to WebP Discussion, James Zern
Thank you for your reply James,

I tried 70 or less, unfortunately with the small PALETTE, it just doesn't look good enough. If I understand you correctly, you are saying there is no way to do vp8 encoding on the alpha channels with cwebp? Or there no way to do vp8 encoding on an alpha channel with any webp encoder? It seems strange that a codec that can do so much high fidelity lossy compression on color channels is so lacking with the alpha channel.

Thank You,
Alex

James Zern

unread,
Aug 2, 2022, 2:21:13 PMAug 2
to WebP Discussion
Hi Alex,

On Tue, Aug 2, 2022 at 9:30 AM Alex Lawson <amlaw...@gmail.com> wrote:
Thank you for your reply James,

I tried 70 or less, unfortunately with the small PALETTE, it just doesn't look good enough. If I understand you correctly, you are saying there is no way to do vp8 encoding on the alpha channels with cwebp? Or there no way to do vp8 encoding on an alpha channel with any webp encoder?

It's not allowed by the format. It could be done, but only in a case where you controlled the end to end encode and decode.
 
It seems strange that a codec that can do so much high fidelity lossy compression on color channels is so lacking with the alpha channel.

You might see some minor improvement with -alpha_filter best. I'm also assuming you're not using -exact; the default allows some modification to transparent pixels. If you have some examples you could share we might be able to look for areas for improvement in the lossless encoder.
Reply all
Reply to author
Forward
0 new messages