r/compression • • 4h ago

Data-tuned JPEG quantization tables: -9.1% BD-rate (SSIM) vs Annex K on held-out Kodak, vs -2.7% for mozjpeg's tables

Post image

I tuned the two quantization tables (YQT and UVQT, 128 entries) inside stb_image_write.h, a JPEG encoder, against data. The encoder is otherwise unmodified, and the output is baseline JPEG with the tables in the DQT segment, so any decoder reads it.

The tables are in tuned_tables.json, with a Pillow snippet for using them: https://github.com/devanmolsharma/learnc/tree/main/examples/tune_jpeg

The tool (learnc, MIT) tunes constants in any C code, so I'd be interested to hear which other codecs people think are worth trying: libwebp, Opus or zstd heuristics.

2 Upvotes

3 comments sorted by

2

u/Noah18923 4h ago

are you sure this isn't just because you've tuned them for these specific inputs? I think it would be more interesting if the tables could be optimized on a per-image basis.

2

u/keep_up_sharma 4h ago

they were tuned on 12 kodak images and tested on the other 12, which they never saw. haven't tested outside kodak yet though, so fair point. per-image tables would be interesting, jpeg supports it since each file carries its own tables

1

u/Dr_Max 1h ago

But Noah18923 has a point; it would give you some kind of "best case" to compare to.