Page 1 of 2

JPEG quantization tables and progressive scan scripts

Posted: 2012-02-28T07:52:46-07:00
by NicolasRobidoux
Would it be possible to add the ability to pass alternative JPEG quantization tables/progressive scan scripts to, say, convert? (I'm pretty sure it's not possible now.)

These features are documented in the wizard.doc file included with the ImageMagick source distro (a copy of the JPEG Group's wizard.txt file).

One possible use (besides my own shenanigans :-)) would be to recompress a medium/low quality JPEG with exactly the quantization table used to create it (figured using, say, http://www.impulseadventure.com/photo/j ... ation.html) to avoid rounding error, chopping off high modes with progressive scan to make the file smaller, and doing this without rounding/truncation error messing up the low modes. What this basically does is remove fine detail without affecting the rest (it's using progressive encoding to perform low pass filtering, reducing file size in the process). (Which sounds like and expert only thing to do, but is actually pretty straightforward if one is provided with step-by-step instructions.) A similar dirty trick is that you could figure out which quantization table to use to re-encode so that integers mostly land on integers (that is, so that rounding is minimized), with a different overall quality setting (this particular dirty trick definitely requires some math), the simplest version being multiplying all entries of the "incoming" effective table resulting from the quantization/quality combination by 2, and then using -quality 100, to reduce file size and quality a big notch.

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-02-28T08:16:09-07:00
by magick
Sure, we'll code up support, perhaps this weekend.

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-02-28T09:21:35-07:00
by NicolasRobidoux
@magick: Many thanks!

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-02-29T17:55:50-07:00
by magick
Here's a peek at the new JPEG quantization tables invoked with "-define jpeg:q-table=myQTables.xml":

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>

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-02-29T18:51:14-07:00
by magick
The custom JPEG quantization table support is in ImageMagick 6.5.7-8 Beta, available by sometime tomorrow. Let us know have any suggestions concerning how we activate custom quantization tables (currently -define jpeg:q-table=path) or the format of the custom quantization table in XML. We include a sample quantization table in the ImageMagick distribution and call it quantization-table.xml. If you have a better name, let us know.

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-03-01T06:06:03-07:00
by NicolasRobidoux
Many many thanks magick.

Will look into it ASAP.

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-03-09T07:29:45-07:00
by lorents
Good afternoon!
Prompt, how it is possible to optimize jpeg through huffman table?

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-03-09T09:13:00-07:00
by NicolasRobidoux
lorents wrote:...how it is possible to optimize jpeg through huffman table?
Optimizing the Huffman tables is on by default. You can turn this optimization off (although why you'd do this is beyond me). See

Code: Select all

-define jpeg:optimize-coding=false
at http://www.imagemagick.org/Usage/formats/#jpg_write

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-03-09T10:32:03-07:00
by lorents
I have not much other situation, I mean as it is possible to touch all possible huffman table values and to create JPEG optimize c in the smallest size?

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-05-23T03:07:42-07:00
by cuongnh
Is there some code MagickCore or Magick++ code equivalent with this ?

-define jpeg:q-table=path

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-05-23T04:39:17-07:00
by magick
In MagickCore, use SetImageOption(). In Magick++, use defineValue().

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-05-28T19:01:34-07:00
by cuongnh
Sorry

Could I use array instead of path to use quantization table in Magick Core

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-05-28T19:31:41-07:00
by cuongnh
I mean may be it's array of quantization tables. Dont need to write quantization which i compute to xml file.

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-05-28T23:34:45-07:00
by anthony
You must write it to a xml file in the format that is exampled (see above).

Re: JPEG quantization tables and progressive scan scripts

Posted: 2012-06-20T19:39:13-07:00
by cuongnh
Hello

I meet this bug and hope some one can fix for me.

My code:

Code: Select all

SetImageOption(image_info, "jpeg:q-table","quantization-table.xml");
When I use lib on cygwin which I download from home page or I build by myself I meet this bug

$ ./Magick_Compress.exe Adobe1.jpg resize.jpg
1 [sig] Magick_Compress 1576 open_stackdumpfile: Dumping stack trace to Ma
gick_Compress.exe.stackdump

But I use this library: CORE_RL_magick_.lib bug is fixed. So How I can use on cygwin?