I would like to know how IM estimates the JPEG Quality.
I took a look at the code in jpeg.c, and it obviously calculates it from the DQT (around line 922). I know about the way how quality is translated into DQT as suggested by the IJG. But to my knowledge the IJG made no suugestion for the other way round. The code in jpeg.c is not commented and inunderstandable to me. Is there an explication / scientific article somewhere?
Estimating JPEG Quality
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Estimating JPEG Quality
Wolfgang Hugemann
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Re: Estimating JPEG Quality
I took a closer look at the code and found out myself: Basically, IM calculates the sum of all DQT entries and compares it directly to the sum of the IJG table entries, which is pre-calculated and stored in the vector sums[101]. The same is done for the sums of the two table entries no. 2 and 53, which are compared to the sum of the corresponding entries of the IJG DQT, stored in hash[101].
If this "hash" is identical to one of those stored in hash[101], the JPEG is assumed to use the IJG tables, and the guess on the quality is assumed to be exact. Otherwise it is characterised as approximate.
This approach is also found in http://www.hackerfactor.com/src/jpegquality.c, where the average of the entries serves the same purpose.
I cloned the code of JPEGsnoop (https://www.impulseadventure.com/photo/jpeg-snoop.html) from GitHub and saw that it performs the job a little more sophisticated: It calculates the ratio of each table entry to the corresponding entry in standard tables from annex K of the JPEG standard and derives the scale factor as well as a variance from that. The variance tells, how far the DQT of the JPEG is off-standard and how reliable the estimation of the quality thus is. (The code is around line 4600 of JfifDecode.cpp.)
I see that the code in IM's jpeg.c is very old and probably will not be touched anymore, but there seems to be room for future enhancement.
If this "hash" is identical to one of those stored in hash[101], the JPEG is assumed to use the IJG tables, and the guess on the quality is assumed to be exact. Otherwise it is characterised as approximate.
This approach is also found in http://www.hackerfactor.com/src/jpegquality.c, where the average of the entries serves the same purpose.
I cloned the code of JPEGsnoop (https://www.impulseadventure.com/photo/jpeg-snoop.html) from GitHub and saw that it performs the job a little more sophisticated: It calculates the ratio of each table entry to the corresponding entry in standard tables from annex K of the JPEG standard and derives the scale factor as well as a variance from that. The variance tells, how far the DQT of the JPEG is off-standard and how reliable the estimation of the quality thus is. (The code is around line 4600 of JfifDecode.cpp.)
I see that the code in IM's jpeg.c is very old and probably will not be touched anymore, but there seems to be room for future enhancement.
Wolfgang Hugemann