Re: Alternatives for Extracting EXIF and JPEG Data from Images

Discussion in 'Python' started by Max Erickson, Mar 5, 2007.

  1. Max Erickson

    Max Erickson Guest

    Roger <> 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
    Max Erickson, Mar 5, 2007
    #1
    1. Advertising

  2. Max Erickson

    Roger Guest

    Max Erickson wrote:
    > Roger <> 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
    Roger, Mar 5, 2007
    #2
    1. Advertising

  3. Max Erickson

    Roger Guest

    Max Erickson wrote:
    > Roger <> 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
    Roger, Mar 5, 2007
    #3
  4. Max Erickson

    Terry Reedy Guest

    "Roger" <> wrote in message
    news:...
    | Max Erickson wrote:
    | > I don't know what the format is, etc, but jpegs I open with PIL have a
    | > quantization attribute, e.g:
    | >
    | >>>> im.quantization

    | Thank you, I wasn't aware of the quantization method. I was unable to
    | find any documentation for it.

    The builtin dir(ob) function returns a list of attributes of ob. Great for
    discovering things that are not documented.

    tjr
    Terry Reedy, Mar 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmFjZWsgU3Rhd2lja2k=?=

    Extract EXIF infromation from JPEG file

    =?Utf-8?B?SmFjZWsgU3Rhd2lja2k=?=, Aug 5, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    555
    =?Utf-8?B?SmFjZWsgU3Rhd2lja2k=?=
    Aug 5, 2005
  2. Vladish

    Reading EXIF info from JPEG

    Vladish, May 4, 2005, in forum: C Programming
    Replies:
    2
    Views:
    452
    Richard Bos
    May 9, 2005
  3. Roger
    Replies:
    0
    Views:
    328
    Roger
    Mar 4, 2007
  4. Arnaud Delobelle

    How to get Exif data from a jpeg file

    Arnaud Delobelle, May 16, 2009, in forum: Python
    Replies:
    3
    Views:
    2,699
    BJ Swope
    May 18, 2009
  5. Reginald Johnson

    Javascript to Access JPEG Metadata XMP, IPTC, EXIF

    Reginald Johnson, Apr 22, 2006, in forum: Javascript
    Replies:
    1
    Views:
    197
    Richard Cornford
    Apr 23, 2006
Loading...

Share This Page