JPEG quantization tables and progressive scan scripts
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
JPEG quantization tables and progressive scan scripts
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.
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.
Last edited by NicolasRobidoux on 2012-05-23T06:33:12-07:00, edited 5 times in total.
Re: JPEG quantization tables and progressive scan scripts
Sure, we'll code up support, perhaps this weekend.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: JPEG quantization tables and progressive scan scripts
@magick: Many thanks!
Re: JPEG quantization tables and progressive scan scripts
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
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.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: JPEG quantization tables and progressive scan scripts
Many many thanks magick.
Will look into it ASAP.
Will look into it ASAP.
Re: JPEG quantization tables and progressive scan scripts
Good afternoon!
Prompt, how it is possible to optimize jpeg through huffman table?
Prompt, how it is possible to optimize jpeg through huffman table?
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: JPEG quantization tables and progressive scan scripts
Optimizing the Huffman tables is on by default. You can turn this optimization off (although why you'd do this is beyond me). Seelorents wrote:...how it is possible to optimize jpeg through huffman table?
Code: Select all
-define jpeg:optimize-coding=false
Re: JPEG quantization tables and progressive scan scripts
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
Is there some code MagickCore or Magick++ code equivalent with this ?
-define jpeg:q-table=path
-define jpeg:q-table=path
Re: JPEG quantization tables and progressive scan scripts
In MagickCore, use SetImageOption(). In Magick++, use defineValue().
Re: JPEG quantization tables and progressive scan scripts
Sorry
Could I use array instead of path to use quantization table in Magick Core
Could I use array instead of path to use quantization table in Magick Core
Re: JPEG quantization tables and progressive scan scripts
I mean may be it's array of quantization tables. Dont need to write quantization which i compute to xml file.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: JPEG quantization tables and progressive scan scripts
You must write it to a xml file in the format that is exampled (see above).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: JPEG quantization tables and progressive scan scripts
Hello
I meet this bug and hope some one can fix for me.
My code:
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?
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");
$ ./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?