Knowing which chroma-subsampling was used in a JPEG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Knowing which chroma-subsampling was used in a JPEG

Post by rnbc »

Hello!

Is there any way, with identify for example, of knowing which chroma-subsampling was used in a certain JPEG file?

Thanks.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Knowing which chroma-subsampling was used in a JPEG

Post by Drarakel »

Code: Select all

identify -verbose image.jpg
Example output:
...
jpeg:sampling-factor: 2x2,1x1,1x1

Or just use:

Code: Select all

identify -format "%[jpeg:sampling-factor]" image.jpg
Note:
Both commands take these factors as image attribute (could be stored in other places). So, this would be possible, too:

Code: Select all

convert rose: rose.jpg
convert rose.jpg rose.png
identify -format "%[jpeg:sampling-factor]" rose.png
2x2,1x1,1x1
Here, it's of course no real sampling-factor! :wink:

You can also use:

Code: Select all

identify -debug coder -log "%e" image.jpg
These commands usually give the sampling-factors for all channels. So, if you have "2x2,1x1,1x1" in a YCbCr (RGB) image, then the Chroma (Cb and Cr) has a subsampling of 2x2.
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Knowing which chroma-subsampling was used in a JPEG

Post by rnbc »

Many thanks!

Weird as it may seem I hadn't seen the -verbose option (duh!!!) when looking at the -help output... :roll:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Knowing which chroma-subsampling was used in a JPEG

Post by fmw42 »

see http://www.imagemagick.org/Usage/basics/#controls and http://www.imagemagick.org/script/identify.php

also see

YCbCrSubSampling

from EXIF tags at http://www.imagemagick.org/script/escape.php

convert image -format "%[EXIF:YCbCrSubSampling]" info:
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Knowing which chroma-subsampling was used in a JPEG

Post by Drarakel »

fmw42 wrote:YCbCrSubSampling

from EXIF tags at http://www.imagemagick.org/script/escape.php

convert image -format "%[EXIF:YCbCrSubSampling]" info:
Though this tag is usually for TIFF files - not for JPG files.

Regarding TIFF:
1) The above code doesn't work (even for 'JPG in TIFF' files that have this tag). IM can't output these EXIF tags in TIFF directly.
2) IM translates the info from the EXIF tags in TIFF partly into 'tiff:', 'jpeg:' or 'photoshop:' attributes. So, one can retrieve the info from the YCbCrSubsampling tag again with "identify -format "%[jpeg:sampling-factor]" image.tif". For example, if the stored values in the tag are "2 2", then IM displays that as "jpeg:sampling-factor: 2x2".
3) But even this info will be wrong for most of the 'JPG in TIFF' files that IM creates. Most of these files can't use subsampling anyway (the sampling-factor will be just 1x1). See my report here.

So, sadly there is no easy way to retrieve the real sampling-factor for JPG compression in TIFF.
Post Reply