Return to Digital Photography Articles
JPEG Compression Quality from Quantization Tables
DQT / Quantization Matrix / JPEG Compression Quality tables for Digital Cameras and Digital Photography Software.
Index of Quantization Table Sources
Would you like to compare two quantization tables?
Want to extract a quantization table or detect a forged/edited photo??
For some background on quantization tables and their use in JPEG compression, please see my JPEG compression article.
For examples and description of the breakdown of an image into 8x8 blocks, please see my article on the JPEG Minimum Coded Unit.
In JPEG compression, the quantization step is performed just prior to the JPEG Huffman Coding.
Example of a Quantization Table
The following diagram shows a typical luminance DQT found in a high-quality digital photo. Note that the numbers increase in magnitude as one approaches the bottom-right corner, which describes the amount of compression (loss) applied to high-frequency image components. Numbers towards the top-left corner (low-frequency & "DC") decrease as we typically don't want to discard this image information as the human visual system will tend to notice "errors" here.
Comparison of Quantization Tables
In trying to evaluate the differences between different software packages and their "quality settings" when saving to JPEG, I have extracted the quantization tables used in each case. In order to do this, I have used my JPEGsnoop utility which locates the offset of the JFIF marker tags within each image, and then extracts the linear stream of bytes from this marker, recreated the zig-zag representation of the quantization (DQT) coefficient matrix and have presented the results here.
In each of the following examples, when I make a reference to "better quality" it is meant in the sense of less quantization error (compression error / loss) and therefore better resulting image quality. The converse is true for "worse quality". The baseline for each of these "better / worse" comparisons is the original digital camera photo as produced by my Canon 10d digital SLR in Fine JPG mode. This helps give one an idea of a comparable quality setting to that used from the camera itself.
Compare JPEG Quality of Digicams and Software
Please check out my JPEG Compression Quality comparison page, where you can interactively compare the quantization tables of different sources!
These are the quantization table / matrix coefficients that are recommended / suggested in the Annex of the JPEG standard.
The JPEG quality range for Photoshop CS2 runs from 1-12. It is expected that this range was used to give the user an idea that 10 is really the most anyone should use, and that 11 and 12 are there purely for experimental reasons (not much gain in quality for a large increase in file size).
Note that the quantization tables generated from a save within Photoshop CS are concatenated together into a single quantization table of length 132 instead of the 2 x 67 that we see in other software programs and the digital camera itself.
- One should realize that none of Photoshop's quality settings in the Save As dialog box will match any digital camera's JPEG compression tables. Therefore, you cannot avoid recompression error when resaving an image from a digicam in Photoshop!
Photoshop CS2 Chroma Subsampling
Note that Photoshop changes its use of chroma subsampling depending upon the image Quality setting in the Save dialog. Photoshop CS2 uses 1x1 (no chroma subsampling) in Quality 7-12, but 2x2 (chroma subsampling in both horizontal and vertical directions) in Quality 0-6. Note that this use of chroma subsampling throws away significantly more image information than the subsampling used by most digital cameras (except some basic digital Point & Shoot digicams).
Photoshop only offers 2x2 or 1x1 (none) chroma subsampling. Most digital cameras use 2x1 chroma subsampling. Therefore, you will have to either choose to over-compensate in the color channels (by doubling the horizontal color resolution of the original source) or discard (by eliminating / averaging the color resolution in the vertical component). I don't know why Adobe didn't choose to provide a saving option that would be closer to what digicams use — better yet, a choice in chroma subsampling, like IrfanView.
A Caution Regarding Photoshop Quality 7!
What many people don't know is that there is a quirk in the way that Photoshop defines its quality range. As mentioned earlier, Quality level 6 is the last point in which chroma subsampling is used. At Quality level 7 and higher, no chroma subsampling is used at all. With the amount of color information encoded now doubled, the file size would have naturally increased significantly at this level versus the previous level.
However, it is likely that Adobe decided to allocate the various quality levels with some relationship to the final compressed file size. Therefore, Adobe chose a poorer luminance and chrominance compression quality (i.e. higher level of compression) in Quality level 7 than Quality level 6!
- What this means is that the image quality of Quality level 7 is actually
lower than Quality level 6
(at least from luminance detail perspective).
This fact has apparently been confirmed with subjective MOS scores against various images at both quality levels.
The only advantage of image quality 7 over quality 6 is that the chrominance detail hasn't been subsampled. So, there is perhaps some degree of benefit to the ability to resolve color information over the previous level, but this benefit is also diminished somewhat by the higher-compressed chrominance table.
You can see the above juxtaposition in the JPEG Quality comparison list.
Photoshop CS2 Quality vs File Size
The following graph shows the relationship between the file size of a typical 6 megapixel photo (from a Canon 10d) and the quality setting selected within Photoshop CS2.
NOTE: There are many reasons why one should not take file size as any indication of a quality comparison. The most important reasons being: different quantization tables, different huffman tables / optimization, orientation differences and additional metadata stored within the JPEG JFIF file.
- With Quality 10, the level of compression is "worse" than that used in the digital camera.
- Using Quality 12, results in "better" quality than the original Canon 10d digital camera photo.
Canon Digital Cameras
- Canon 1Ds Mark II - This camera uses the least amount of JPEG compression (and thus highest quality) of any of Canon's digital SLRs.
- Canon 1D Mark II - Not surprisingly, this camera uses the second to least amount of JPEG compression of any of Canon's digital SLRs.
- Canon 5d - There are extremely small differences in the luminance table in the Canon 5d versus the 30d/20d.
- Canon 30d, Canon 20d, Canon 10d (Fine Mode)- All of the prosumer line uses the same set of tables. One can see that the degree of quantization rounding used in Fine mode is quite minimal, ie. there is not much compression loss at this setting.
- Canon 30d, Canon 20d, Canon 10d (Normal Mode) - In Normal mode, the quality suffers quite significantly, putting it at worse compression than just about any other digicam's Fine mode.
- Canon PowerShot S3 IS - The Canon PowerShot S3 IS has comparable luminance compression as to the Canon 10d, but considerably worse chrominance compression. However, it is still much better than the Canon PowerShot SD400 in this regard.
- Canon PowerShot SD400 - Typical for a point and shoot digital camera, the JPEG compression quality is lower than the digital SLR counterparts.
Sony Digital Cameras
- Sony DSC H9 - Interestingly enough, it appears that the Sony DSC H9 is one of the first cameras that I have come across that use automatic / variable image compression. The quantization tables are selected at exposure time by the camera, rather than relying on a couple-position user level setting. This has some very interesting implications. I am currently in the process of analyzing images from this camera to understand the reasoning and algorithm that is being used. Please see the Variable JPEG Compression page for more details on this camera's feature.
Sigma Digital Cameras
- Sigma SD10 - Note that there is no chroma subsampling in the Sigma dSLRs with the Foveon sensor. In addition, there is extremely little compression being used on this camera when compared to other dSLRs.
Nikon Digital Cameras
- Nikon D2x - Interestingly enough, it seems that the Nikon D2x and Sigma SD10 share the same quantization tables and hence compression quality.
- The JPEG quality range for IrfanView runs from 0 to 100.
- At quality setting 97, IrfanView uses slightly "worse" compression than the original Canon 10d digital photo.
- At quality setting 98, IrfanView uses slightly "better" compression than the original digital camera photo.