JPEG quantization tables and progressive scan scripts

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
cuongnh
Posts: 12
Joined: 2012-05-23T03:05:20-07:00
Authentication code: 13

Re: JPEG quantization tables and progressive scan scripts

Post by cuongnh » 2012-06-20T19:45:43-07:00

Here is mycode

Code: Select all

(void) strcpy(image1->filename, "resize.pnm");
    WriteImage(image_info, image1);

    (void)strcpy(image_info->filename,"resize.pnm");
    
    SetImageOption(image_info, "jpeg:q-table","quantization-table.xml");
    image2 = ReadImage(image_info,exception);

    
    (void) strcpy(image2->filename, "resize3-11-table.jpg");

    WriteImage(image_info, image2);

User avatar
anthony
Posts: 8871
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: JPEG quantization tables and progressive scan scripts

Post by anthony » 2012-07-15T20:59:20-07:00

I believe you will need to set it as a image artifact.


I have been looking into this as part of IMv7 CLI development.

There are three sets of 'free-form strings' holding mete-data.

Options (image_info) whcih is used to hold user defined global options (across all images).
In command line these are also automatically converted into image artifacts (see below)
Also in CLI -define sets these, as does -set option:....

Properities (image) whcih hold free-form image meta-data that should be saved with the image (if possible).
in command line -set sets these strings. This includes "label" "comment", and the file "date-*" time stamps.

Artifacts (image) which are per-image controls and settings that should NOT be saved with the image.
Typically used for holw coder and operational settings, such as "jpeg:q-table".

In command line "Options" such as "background" "delay" "compose" are copied into "Artifacts" as often a core library operation only has access to the image structure and not the associated image_info structure.

In IMv7, I am looking to replace that copy with a (temporary and non-permanent) link from image structure to the associated image_info structure. But that means that any 'artifact' lookup, should first look at per-image Artifacts, then automatically fall back to looking up a global 'image_info' option. This is a drastic change but one I feel nessary to remove the current constant copiying that CLI is performing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-09T10:19:34-07:00

convert -define jpeg:q-table=myQTables.xml test.bmp a1.jpeg is not working for me. pls help

where myQTables.xml is stored in the same directory and its content is:

Code: Select all

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE quantization-tables [
    <!ELEMENT quantization-tables (table)+>
    <!ELEMENT table (description , levels)>
    <!ELEMENT description (CDATA)>
    <!ELEMENT levels (CDATA)>
    <!ATTLIST table slot ID #REQUIRED>
    <!ATTLIST levels width CDATA #REQUIRED>
    <!ATTLIST levels height CDATA #REQUIRED>
    <!ATTLIST levels divisor CDATA #REQUIRED>
    ]>
    <!--
      JPEG quantization tables.
    -->
    <quantization-tables>
      <table slot="0" alias="luminance">
        <description>Luminance Quantization Table</description>
        <levels width="8" height="8" divisor="1">
          16, 12, 14, 17, 22, 30, 45, 72,
          12, 13, 14, 17, 22, 31, 46, 74,
          14, 14, 16, 19, 25, 35, 52, 83,
          17, 17, 19, 23, 30, 41, 62, 100,
          22, 22, 25, 30, 39, 54, 80, 129,
          30, 31, 35, 41, 54, 74, 111, 178,
          45, 46, 52, 62, 80, 111, 166, 267,
          72, 74, 83, 100, 129, 178, 267, 428
        </levels>
      </table>

      <table slot="1" alias="chrominance">
        <description>Chrominance Quantization Table</description>
        <levels width="8" height="8" divisor="1">
          17,  18,  22,  31,  50,  92,   193,  465,
          18,  19,  24,  33,  54,  98,   207,  498,
          22,  24,  29,  41,  66,  120,  253,  609,
          31,  33,  41,  57,  92,  169,  355,  854,
          50,  54,  66,  92,  148, 271,  570,  1370,
          92,  98,  120, 169, 271, 498,  1046, 2516,
          193, 207, 253, 355, 570, 1046, 2198, 5289,
          465, 498, 609, 854, 1370,2516, 5289, 12725
        </levels>
      </table>
    </quantization-tables>
  • convert -define jpeg:q-table=myQTables.xml test.bmp a1.jpeg
is not working for me. pls help

after running this in command line , i displayed the quantization table, using the following python code

Code: Select all

im2=Image.open('a1.jpeg')

print "a1 QT table"
print im2.quantization
and it displays :
  • {0: array('b', [3, 2, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3, 3, 3, 4, 6, 4, 4, 4, 4, 4, 8, 6, 6, 5, 6, 9, 8, 10, 10, 9, 8, 9, 9, 10, 12, 15, 12, 10, 11, 14, 11, 9, 9, 13, 17, 13, 14, 15, 16, 16, 17, 16, 10, 12, 18, 19, 18, 16, 19, 15, 16, 16, 16])}
which is some default quantization table :(

User avatar
magick
Site Admin
Posts: 10841
Joined: 2003-05-31T11:32:55-07:00

Re: JPEG quantization tables and progressive scan scripts

Post by magick » 2013-10-09T10:34:19-07:00

These commands suggest the custom quantization tables are working properly:
  • # convert -define jpeg:q-table=myQTables.xml test.bmp a1.jpeg
    # ls -l a1.jpeg
    rw-r--r-- 1 magick magick 60945 Oct 9 13:24 a1.jpeg
    # convert test.bmp a1.jpeg
    # ls -l a1.jpeg
    rw-r--r-- 1 magick magick 58699 Oct 9 13:24 a1.jpeg
Notice, a1.jpeg is a different size when using custom quantization tables.

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-09T10:49:00-07:00

savyan-K54C% convert -define jpeg:q-table=myQTables.xml baboon.bmp a1.jpeg
savyan-K54C% ls -l a1.jpeg
-rw-rw-r-- 1 savyan savyan 139541 Oct 9 23:16 a1.jpeg
savyan-K54C% convert baboon.bmp a1.jpeg
savyan-K54C% ls -l a1.jpeg
-rw-rw-r-- 1 savyan savyan 139541 Oct 9 23:16 a1.jpeg
savyan-K54C%

this is my output what is may be the reason?

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-09T10:52:11-07:00

savyan-K54C% convert
Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

is the convert version i installed.

But in my system there is no difference , what may be the reason

savyan-K54C% convert -define jpeg:q-table=myQTables.xml baboon.bmp a1.jpeg
savyan-K54C% ls -l a1.jpeg
-rw-rw-r-- 1 savyan savyan 139541 Oct 9 23:16 a1.jpeg
savyan-K54C% convert baboon.bmp a1.jpeg
savyan-K54C% ls -l a1.jpeg
-rw-rw-r-- 1 savyan savyan 139541 Oct 9 23:16 a1.jpeg

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-09T11:10:21-07:00

pls help. :(

User avatar
magick
Site Admin
Posts: 10841
Joined: 2003-05-31T11:32:55-07:00

Re: JPEG quantization tables and progressive scan scripts

Post by magick » 2013-10-09T11:42:50-07:00

Your version of ImageMagick is too old and does not support custom JPEG quantization tables. Not sure when we supported it, but certainly the current release will work @ 6.8.7-0.

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-09T12:02:45-07:00

Thank you, i shall try the new version :)

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-14T23:02:22-07:00

doubt in convert -define:jpeg q-table=myQTable.xml (ver 6.8.7-0)
First i executed the following command:

convert -define jpeg:q-table=myQTables.xml lena512.bmp testing6.jpeg

after executing i displayed the qtable using exiftool and using python both shows which is not the one i gave in the myQTables.xml:
3, 2, 2, 2, 2, 2, 3, 2,
2, 3, 4, 3, 3, 3, 4, 5,
4, 3, 3, 4, 5, 7, 5, 4,
4, 4, 5, 7, 12, 7, 6, 5,
5, 6, 7, 12, 12, 8, 7, 6,
7, 8, 12, 13, 10, 9, 9, 10,
13, 16, 13, 12, 13, 16, 21, 18,
18, 21, 28, 27, 28, 43, 43, 68

but the expected values were
16, 12, 14, 17, 22, 30, 45, 72,
12, 13, 14, 17, 22, 31, 46, 74,
14, 14, 16, 19, 25, 35, 52, 83,
17, 17, 19, 23, 30, 41, 62, 100,
22, 22, 25, 30, 39, 54, 80, 129,
30, 31, 35, 41, 54, 74, 111, 178,
45, 46, 52, 62, 80, 111, 166, 267,
72, 74, 83, 100, 129, 178, 267, 428

i tried with different values in myQTables.xml thecompressed file size is changing each time but the qtable is wrong

I set myQTables.xml as this
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE quantization-tables [
<!ELEMENT quantization-tables (table)+>
<!ELEMENT table (description , levels)>
<!ELEMENT description (CDATA)>
<!ELEMENT levels (CDATA)>
<!ATTLIST table slot ID #REQUIRED>
<!ATTLIST levels width CDATA #REQUIRED>
<!ATTLIST levels height CDATA #REQUIRED>
<!ATTLIST levels divisor CDATA #REQUIRED>
]>
<!--
JPEG quantization tables.
-->
<quantization-tables>
<table slot="0" alias="luminance">
<description>Luminance Quantization Table</description>
<levels width="8" height="8" divisor="1">
16, 12, 14, 17, 22, 30, 45, 72,
12, 13, 14, 17, 22, 31, 46, 74,
14, 14, 16, 19, 25, 35, 52, 83,
17, 17, 19, 23, 30, 41, 62, 100,
22, 22, 25, 30, 39, 54, 80, 129,
30, 31, 35, 41, 54, 74, 111, 178,
45, 46, 52, 62, 80, 111, 166, 267,
72, 74, 83, 100, 129, 178, 267, 428
</levels>
</table>
<table slot="1" alias="chrominance">
<description>Chrominance Quantization Table</description>
<levels width="8" height="8" divisor="1">
17, 18, 22, 31, 50, 92, 193, 465,
18, 19, 24, 33, 54, 98, 207, 498,
22, 24, 29, 41, 66, 120, 253, 609,
31, 33, 41, 57, 92, 169, 355, 854,
50, 54, 66, 92, 148, 271, 570, 1370,
92, 98, 120, 169, 271, 498, 1046, 2516,
193, 207, 253, 355, 570, 1046, 2198, 5289,
465, 498, 609, 854, 1370,2516, 5289, 12725
</levels>
</table>
</quantization-tables>

what is the problem?

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-14T23:13:53-07:00

The exiftool command i used is:

exiftool -v3 testing6.jpeg

its output is :

ExifToolVersion = 8.60
FileName = testing6.jpeg
Directory = .
FileSize = 70424
FileModifyDate = 1381817254
FilePermissions = 33204
FileType = JPEG
MIMEType = image/jpeg
.
.
JPEG DQT (65 bytes):
0018: 00 03 02 02 02 02 02 03 02 02 03 04 03 03 03 04 [................]
0028: 05 04 03 03 04 05 07 05 04 04 04 05 07 0c 07 06 [................]
0038: 05 05 06 07 0c 0c 08 07 06 07 08 0c 0d 0a 09 09 [................]
0048: 0a 0d 10 0d 0c 0d 10 15 12 12 15 1c 1b 1c 2b 2b [..............++]
0058: 44
.
.
.

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-14T23:19:50-07:00

The following python code also gave same result:

from PIL import Image
tst6=Image.open('testing6.jpeg')
print "testing6 QT table"
print tst6.quantization


its output is also:

testing6 QT table
{0: array('b', [3, 2, 2, 2, 2, 2, 3, 2, 2, 3, 4, 3, 3, 3, 4, 5, 4, 3, 3, 4, 5, 7, 5, 4, 4, 4, 5, 7, 12, 7, 6, 5, 5, 6, 7, 12, 12, 8, 7, 6, 7, 8, 12, 13, 10, 9, 9, 10, 13, 16, 13, 12, 13, 16, 21, 18, 18, 21, 28, 27, 28, 43, 43, 68])}
L
('L',)

savyan
Posts: 9
Joined: 2013-10-09T10:08:34-07:00
Authentication code: 6789

Re: JPEG quantization tables and progressive scan scripts

Post by savyan » 2013-10-14T23:43:42-07:00

Thanks all who looked into this problem,

i found out it. It is currect only:

it is the scaled quantization table using the equation QT*scale where scale is 200-2*92(92 is default scaling factor)

:o

Post Reply