stupid pet trick?: JPEG compression with qtable of ones
Posted: 2012-02-26T14:23:03-07:00
P.S. Using a qtable of ones is possibly pushing things too far. Reason: DCT coefficients can range from 0 to 1024. At quality < 95 with the standard qtables, almost all of them are brought within a 256 range. Consequently, cjpeg, I believe, does not bother rescaling. This is consistent with the standard. Using ones (or quality levels above 95 with the standard tables), unfortunately, extreme DCT values may get clamped back toward middle gray. Consequently, the methods proposed in this thread may have quite strong filtering built in. This would be kinda good for very low quality, but not so much for mid to high quality. I'll post the fix in another thread.
Usable JPEG compression with [1,1,1,...,1] as quantization table.
In http://imagemagick.org/discourse-server ... 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:
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 ) To top it off, I actually use -quality 100!
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):
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 runThis will produce a jpg compressed image (fido.jpg) with 8x8 blocks in all channels which is roughly the same size as the one produced with the following cjpeg command, which uses the standard quantization tables and cjpeg's default -sampling-factor 2x2 (16x16 chroma blocks):
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
Usable JPEG compression with [1,1,1,...,1] as quantization table.
In http://imagemagick.org/discourse-server ... 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
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;
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
- 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