Max Erickson wrote: > Roger <[EMAIL PROTECTED]> wrote: > >> Does anybody have a pointer to a Python library/utility that will >> extract the chrominance and luminance quantization tables from >> JPG images? >> >> I have been using the _getexif method from PIL, which works fine, >> but doesn't extract the quantization data. I am a bit fuzzy on >> the terminology, but the quantization data seems to be JPEG data >> rather than EXIF data. One utility that extracts the >> quantization tables is JPEGsnoop -- there is a link to download >> the utility here: >> http://www.impulseadventure.com/photo/jpeg-quantization.html >> >> The source code for the above isn't available and may not be >> callable from a Python script even if it were available. >> >> Roger >> > > I don't know what the format is, etc, but jpegs I open with PIL have a > quantization attribute, e.g: > >>>> im.quantization > {0: array('b', [6, 4, 4, 5, 4, 4, 6, 5, 5, 5, 6, 6, 6, 7, 9, 14, 9, 9, > 8, 8, 9, 18, 13, 13, 10, 14, 21, 18, 22, 22, 21, 18, 20, 20, 23, 26, > 33, 28, > <snip a bunch more numbers> > > > max >
Thank you, I wasn't aware of the quantization method. I was unable to find any documentation for it. The 0: array() output would appear to be the luminance 8x8 array and the 1: array() to be the chrominance 8x8 array. A curiosity is the values disagree with the output of the JPEGsnoop utility. For my Canon Powershot S2 IS set to "fine", im.quantization yields (after formatting): {0: array('b', [ 1, 1, 1, 2, 1, 1, 2, 2, 2, 2, 3, 2, 2, 3, 3, 6, 4, 3, 3, 3, 3, 7, 5, 8, 4, 6, 8, 8, 10, 9, 8, 7, 11, 8, 10, 14, 13, 11, 10, 10, 12, 10, 8, 8, 11, 16, 12, 12, 13, 15, 15, 15, 15, 9, 11, 16, 17, 15, 14, 17, 13, 14, 14, 14 ]), 1: array('b', [ 4, 4, 4, 5, 4, 5, 9, 5, 5, 9, 15, 10, 8, 10, 15, 26, 19, 9, 9, 19, 26, 26, 26, 26, 13, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26])} The JPEGsnoop output for the same jpg file is (pardon the line wrap): Precision=0 bits Destination ID=0 (Luminance) DQT, Row #0: 1 1 1 2 3 6 8 10 AnnexRatio: 16.0 11.0 10.0 8.0 8.0 6.7 6.4 6.1 DQT, Row #1: 1 1 2 3 4 8 9 8 AnnexRatio: 12.0 12.0 7.0 6.3 6.5 7.3 6.7 6.9 DQT, Row #2: 2 2 2 3 6 8 10 8 AnnexRatio: 7.0 6.5 8.0 8.0 6.7 7.1 6.9 7.0 DQT, Row #3: 2 2 3 4 7 12 11 9 AnnexRatio: 7.0 8.5 7.3 7.3 7.3 7.3 7.3 6.9 DQT, Row #4: 3 3 8 11 10 16 15 11 AnnexRatio: 6.0 7.3 4.6 5.1 6.8 6.8 6.9 7.0 DQT, Row #5: 3 5 8 10 12 15 16 13 AnnexRatio: 8.0 7.0 6.9 6.4 6.8 6.9 7.1 7.1 DQT, Row #6: 7 10 11 12 15 17 17 14 AnnexRatio: 7.0 6.4 7.1 7.3 6.9 7.1 7.1 7.2 DQT, Row #7: 14 13 13 15 15 14 14 14 AnnexRatio: 5.1 7.1 7.3 6.5 7.5 7.1 7.4 7.1 Approx quality factor = 92.96 (scaling=14.08 variance=5.28) ---- Precision=0 bits Destination ID=1 (Chrominance) DQT, Row #0: 4 4 5 9 15 26 26 26 AnnexRatio: 4.3 4.5 4.8 5.2 6.6 3.8 3.8 3.8 DQT, Row #1: 4 4 5 10 19 26 26 26 AnnexRatio: 4.5 5.3 5.2 6.6 5.2 3.8 3.8 3.8 DQT, Row #2: 5 5 8 9 26 26 26 26 AnnexRatio: 4.8 5.2 7.0 11.0 3.8 3.8 3.8 3.8 DQT, Row #3: 9 10 9 13 26 26 26 26 AnnexRatio: 5.2 6.6 11.0 7.6 3.8 3.8 3.8 3.8 DQT, Row #4: 15 19 26 26 26 26 26 26 AnnexRatio: 6.6 5.2 3.8 3.8 3.8 3.8 3.8 3.8 DQT, Row #5: 26 26 26 26 26 26 26 26 AnnexRatio: 3.8 3.8 3.8 3.8 3.8 3.8 3.8 3.8 DQT, Row #6: 26 26 26 26 26 26 26 26 AnnexRatio: 3.8 3.8 3.8 3.8 3.8 3.8 3.8 3.8 DQT, Row #7: 26 26 26 26 26 26 26 26 AnnexRatio: 3.8 3.8 3.8 3.8 3.8 3.8 3.8 3.8 Approx quality factor = 88.24 (scaling=23.52 variance=21.42) I don't understand the "AnnexRatio" data JPEGsnoop is adding to each row. Anyone have an explanation on how to translate the im.quantization values to the JPEGsnoop values? Or am I looking at two different types of "quantization" tables? Roger -- http://mail.python.org/mailman/listinfo/python-list