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?".
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Knowing which chroma-subsampling was used in a JPEG

Postby rnbc » 2010-09-27T08:20:10-07:00

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

Postby Drarakel » 2010-09-27T13:16:14-07:00

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

Postby rnbc » 2010-09-27T14:45:31-07:00

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: 15296
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

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

Postby fmw42 » 2010-09-27T15:15:00-07:00

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

Postby Drarakel » 2010-09-27T18:07:10-07:00

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.


Return to “Users”

Who is online

Users browsing this forum: TurnitinBot [Bot], Yahoo [Bot] and 5 guests