Better JPEG luma quantization table
Posted: 2012-02-29T15:39:12-07:00
The following is unquestionably (to me) a better luma quantization table than the stock one:
This new luma quantization table is obtained from the standard luma quantization table as follows:
In following posts, I'll explain the heuristics behind this modification, as well as give code that allows use this customized quantization table with JPEG Group's cjpeg as well as ImageMagick's convert (I am told ImageMagick will be able to use custom qtables soon).
As of now, I issue a
Note that recompressing a very low quality JPEG image and similar endeavors does not really count as a proper response to the challenge. So is recompressing a JPEG produced with the standard table at essentially the same quality level, using unreasonable quality levels, and other splitting hair tasks.
Being smaller by a trivial amount does not really count either.
This challenge has to do with a reasonable "real world" case.
(To those who followed my attempts at improving qtables: The above new luma one is most likely the best I have come up with for all purpose use. I don't think I'll be able to put together a qtable which is significantly better for all purpose use. Exploiting progressive encoding is another story.)
Code: Select all
######################################################################
# Nicolas Robidoux's better luma quantization table v2012.02.29
#
# To be used with, e.g.,
#
# cjpeg -qtables ThisFile.txt -qslots 0,1 \
# -quality YourChosenQuality \
# -dct float -baseline -optimize \
# -outfile OutputImage.jpg InputImage.ppm
#
# The author (Nicolas Robidoux) consults for a living and can dial
# JPEG artifact mixes in a controlled manner, customize jpegrescan,
# etc. Email: FiRsTnAmE dOt LaStNaMe HaT gMaIl DoT cOm.
#
# Suggested improvements and comments are welcome.
#
# The new luma table is a variant of the standard one, first described
# in an annex of ITU-T Recommendation T.81 (the original "JPEG
# standard"). For convenience, the standard chroma table (from the
# same annex) is copied below.
######################################################################
# The new luma table:
16 11 12 15 21 32 50 66
11 12 13 18 24 46 62 73
12 13 16 23 38 56 73 75
15 18 23 29 53 75 83 83
21 24 38 53 68 95 103 103
32 46 56 75 95 104 117 117
50 62 73 83 103 117 120 120
66 73 75 83 103 117 120 120
# The standard chroma table:
17 18 24 47 99 99 99 99
18 21 26 66 99 99 99 99
24 26 56 99 99 99 99 99
47 66 99 99 99 99 99 99
99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99
- First, symmetrize, that is, replace the entry at position (i,j) by the average of the standard entry at the same position and the standard entry at position (j,i), rounding down.
- Then, make the result monotone, that is, fix things so that a higher frequency mode never has a smaller entry than a lower frequency mode. Specifically, this means that the list of entries should be nondecreasing both column wise and row wise.
In following posts, I'll explain the heuristics behind this modification, as well as give code that allows use this customized quantization table with JPEG Group's cjpeg as well as ImageMagick's convert (I am told ImageMagick will be able to use custom qtables soon).
As of now, I issue a
The noncontrived clause has to do with that someone who understands JPEG compression can construct an image specifically to make the standard table win.Challenge: Show me a noncontrived image for which the standard luma qtable gives a smaller file with as good or better image quality than the above new one.
Note that recompressing a very low quality JPEG image and similar endeavors does not really count as a proper response to the challenge. So is recompressing a JPEG produced with the standard table at essentially the same quality level, using unreasonable quality levels, and other splitting hair tasks.
Being smaller by a trivial amount does not really count either.
This challenge has to do with a reasonable "real world" case.
(To those who followed my attempts at improving qtables: The above new luma one is most likely the best I have come up with for all purpose use. I don't think I'll be able to put together a qtable which is significantly better for all purpose use. Exploiting progressive encoding is another story.)