Usable JPEG compression with [1,1,1,...,1] as quantization table.
In http://imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333, I discuss numerous attempts at improving JPEG compression quantization matrices, many of them in the -sampling-factor 1x1 case. (I'd like to avoid the 2x2 colour artifacts caused by chroma blocks larger than luma blocks, artifacts which may be quite severe at reasonable quality.)
If you've followed the above thread, it may come as a surprise that I'm quite happy with the following quantization matrix:
- Code: Select all
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
That is: 64 ones, used for the Y (luma) as well as the Cb and Cr (chroma) channels. You read me right: I use a quantization matrix which is absolutely not recommended by the JPEG Group since it corresponds to -quality 100, which may suggest to some that I've lost my mind. (Well, maybe, but this is another story
Key trick: Use progressive encoding to scale the DCT coefficients.
Cjpeg example which actually does work quite well with -sample 1x1, the equivalent of ImageMagick's -sampling-factor 1x1.
Save the above matrix of ones in a text file ("qtable.txt", for example). Also save what's below in another text file ("scans.txt", for example):
- Code: Select all
# Nicolas Robidoux's progressive encoding v2012.02.26
# for -sample 1x1 (too few chroma values for 2x2)
0: 0 0 0 3;
1: 0 0 0 3;
2: 0 0 0 2;
0: 1 1 0 2;
0: 2 2 0 2;
2: 1 2 0 2;
0: 3 5 0 2;
1: 1 2 0 3;
0: 6 20 0 3;
0: 21 35 0 4;
0: 36 63 0 5;
To use this qtable/scans pair, create a ppm file (cjpeg is fairly limited w.r.t. what formats it eats), calling it "original.ppm", say, and run
- Code: Select all
cjpeg -baseline -optimize -dct float -quality 100 -sample 1x1 -scans scans.txt -qtables qtable.txt -qslots 0 -outfile fido.jpg original.ppm
- Code: Select all
cjpeg -baseline -optimize -dct float -quality 78 -outfile stock.jpg original.ppm
Now, the fido.jpg image, although it is IMHO roughly of the same quality, differs in character in a number of ways (which I like) from the stock image, the main two being
- Effectively, a low pass filter is applied to it, and consequently it shows less "JPEG block ripples"
and fine details
than the image produced with the standard.
Overall, the result looks much better when enlarged than the stock image (unless you want fine detail, of course). - it not show the usual wide "red/green bands/checkerboard artifacts" associated with -sampling-factor 2x2.
- Code: Select all
convert bedroom_huffman.jpg original.ppm