4:2:0 JPEG chroma subsampling
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
4:2:0 JPEG chroma subsampling
Does anyone know how the chroma subsampling for JPEG 4:2:0 compression is done within IM?
Are the chroma channels averaged one group of four (2x2) pixels at a time? Or is some variant of nearest neighbour used? Is box filtering part of the standard?
I am wondering if using another low-pass filter than box filtering with the CbCr channels (Cubic or Quadratic (cubic or quadratic B-spline smoothing or its distort variant) or gaussian blur) and then using 4:4:4 (no chroma subsampling) instead of 4:2:0 but with a lower quality level would give better results (for a given file size).
The logic is that the Discrete Cosine Transform "converges" the fastest when the input is smoothest (including, unfortunately, the "periodic extension" of the input data). Given that box filtering is not that good of a low-pass filter, the gain in convergence rate obtained by a better chroma "smoother" may beat the fact that box filtering can be used to halve the sampling rate, and further more lead to more localized artifacts (8x8 blocks in chroma instead of 16x16).
Are the chroma channels averaged one group of four (2x2) pixels at a time? Or is some variant of nearest neighbour used? Is box filtering part of the standard?
I am wondering if using another low-pass filter than box filtering with the CbCr channels (Cubic or Quadratic (cubic or quadratic B-spline smoothing or its distort variant) or gaussian blur) and then using 4:4:4 (no chroma subsampling) instead of 4:2:0 but with a lower quality level would give better results (for a given file size).
The logic is that the Discrete Cosine Transform "converges" the fastest when the input is smoothest (including, unfortunately, the "periodic extension" of the input data). Given that box filtering is not that good of a low-pass filter, the gain in convergence rate obtained by a better chroma "smoother" may beat the fact that box filtering can be used to halve the sampling rate, and further more lead to more localized artifacts (8x8 blocks in chroma instead of 16x16).
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 4:2:0 JPEG chroma subsampling
Im does not handle that at all. It is controlled by a delegate JPEG library.
The JPEG coder module will pass some controls to the library..
http://www.imagemagick.org/Usage/formats/#jpg_write
"2x2, 1x1, 1x1" is IM's standard subsampling method and corresponds to 4:2:0 Chroma sub-sampling.
The JPEG coder module will pass some controls to the library..
http://www.imagemagick.org/Usage/formats/#jpg_write
"2x2, 1x1, 1x1" is IM's standard subsampling method and corresponds to 4:2:0 Chroma sub-sampling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: 4:2:0 JPEG chroma subsampling
Note sure I am controlling the chroma subsampling correctly, but here
is my first attempt. At this point, it appears that prefiltering the
chroma is not worth the bother.
(Code removed because outdated.)
is my first attempt. At this point, it appears that prefiltering the
chroma is not worth the bother.
(Code removed because outdated.)
Last edited by NicolasRobidoux on 2011-04-14T11:33:14-07:00, edited 4 times in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 4:2:0 JPEG chroma subsampling
The default is the standard
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: 4:2:0 JPEG chroma subsampling
When "quality" is 90 or higher, the channels are not subsampled when writing a JPEG.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: 4:2:0 JPEG chroma subsampling
Thank you Glenn (and Anthony).glennrp wrote:When "quality" is 90 or higher, the channels are not subsampled when writing a JPEG.
This explains why the file size gain is larger when the quality is >= 90.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: 4:2:0 JPEG chroma subsampling
It appears to me that if you don't explicitly specify the -sampling-factor, you do NOT get chroma subsampling at any quality level.
It is my opinioni that this is NOT a good thing.
It is my opinioni that this is NOT a good thing.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 4:2:0 JPEG chroma subsampling
I noted that in IM examples on that jpeg define.glennrp wrote:When "quality" is 90 or higher, the channels are not subsampled when writing a JPEG.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 4:2:0 JPEG chroma subsampling
NicolasRobidoux wrote:It appears to me that if you don't explicitly specify the -sampling-factor, you do NOT get chroma subsampling at any quality level.
It is my opinioni that this is NOT a good thing.
You could have a look at the coder source.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/