Page 1 of 1
Knowing which chroma-subsampling was used in a JPEG
Posted: 2010-09-27T08:20:10-07:00
by rnbc
Hello!
Is there any way, with identify for example, of knowing which chroma-subsampling was used in a certain JPEG file?
Thanks.
Re: Knowing which chroma-subsampling was used in a JPEG
Posted: 2010-09-27T13:16:14-07:00
by Drarakel
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!
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.
Re: Knowing which chroma-subsampling was used in a JPEG
Posted: 2010-09-27T14:45:31-07:00
by rnbc
Many thanks!
Weird as it may seem I hadn't seen the
-verbose option (duh!!!) when looking at the
-help output...

Re: Knowing which chroma-subsampling was used in a JPEG
Posted: 2010-09-27T15:15:00-07:00
by fmw42
Re: Knowing which chroma-subsampling was used in a JPEG
Posted: 2010-09-27T18:07:10-07:00
by Drarakel
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.