10

I have been using ImageMagick command line tool for jpeg compression of the images. However, I'm trying to understand the role of sampling factor. It says the sampling factor is used to specify the block size i.e. 8x8 or 16x16. However, I can't find the default values used if I omit this parameter.

Also, I tried fetching properties of an image by using the following command:

identify -verbose image.jpg

It shows sampling factor values as 1x1, 1x1, 1x1. What does it mean? Either it should be 8x8 or 16x16 or 32x32....

Could anyone please give me an idea where to find these details?

pree
  • 2,297
  • 6
  • 37
  • 55

1 Answers1

10

From ImageMagick's command line options:

-sampling-factor

This option specifies the sampling factors to be used by the JPEG encoder for chroma downsampling. If this option is omitted, the JPEG library will use its own default values.

Here is a good thread.. on Knowing which chroma-subsampling was used in a JPEG

Chroma Subsampling in JPG Compression

I hope this helps :)

tricasse
  • 1,299
  • 13
  • 18
Iamiuru
  • 469
  • 3
  • 6
  • 1
    Thank you for posting these useful links. I'm actually trying to correlate it with the following definition I found. -sampling-factor {horizontal}x{vertical} Adjust the sampling factor used by JPEG library for chroma down sampling. This can be set to '2x1' for creating MPEG-2 animation files. "2x2, 1x1, 1x1" is IM's standard sub-sampling method and corresponds to 4:2:0, see Wikipedia, Chroma Sub-Sampling. However when "quality" is 90 or higher, the channels are not sub-sampled. Basically it will define whether the processing 'block' or 'cell' size is 8 pixels or 16 pixels. – pree Apr 08 '13 at 19:16
  • Does -sampling-factor 1x1 mean 8x8 block size and 2x2 mean 16x16 block size. Or I'm not understanding it correctly? – pree Apr 08 '13 at 19:19
  • 1
    From: (http://www.ftgimp.com/help/C/filters/jpeg.html) "2x2,1x1,1x1 downsamples both the Cr and Cb channels by half" (http://dougkerr.net/pumpkin/articles/Subsampling.pdf) Starting on page 9 there is some good info.. "there are four 8-bit values, designated H1, V1, H2, V2, H3, and V2. Each pair (e.g., H1 and V1) is listed in the portion of the marker pertaining to one of the three “components” of the image, Y, Cb, and Cr." `H1 V1 H2 V2 H3 V3 J:a:b h/v 2 2 1 1 1 1 4:2:0 2/2` YCbCr 2x1 1x1 1x1 where the six numerical values are H1, V1; H2, V2; and H3, V3 – Iamiuru Apr 09 '13 at 04:57
  • 1
    From what I could find jpegs are 8x8... the 16x16/16x8 is for movies, not images. 8x8 works for movies also. So I think the answer to the question is 2x2,1x1,1x1 is not directly related to 8x8 vs 16x16. (http://white.stanford.edu/~brian/psy221/reader/Wallace.JPEG.pdf) There is no reference to 16x16 in the JPEG standard. – Iamiuru Apr 09 '13 at 05:03
  • One follow up question, do you know what block size is used in ImageMagick for JPEG compression? I tried finding it but it's nowhere documented. – pree Apr 11 '13 at 16:53
  • 2
    Minimum coded unit, the pixel block size of JPEG image used for coding; usually 8×8 pixels for grayscale and 4:4:4 format, and 16×16 pixels for YCbCr 4:2:0 color JPEG image. From http://en.wikipedia.org/wiki/MCU. I was wrong about only 8x8... but you're right.. not much data out there on this. Since we know "2x2, 1x1, 1x1" = 4:2:0.. then 16x16 it is – Iamiuru Apr 11 '13 at 18:42
  • You are right. I found this link: http://en.wikipedia.org/wiki/JPEG. It says "After subsampling, each channel must be split into 8×8 blocks. Depending on chroma subsampling, this yields (Minimum Coded Unit) MCU blocks of size 8×8 (4:4:4 – no subsampling), 16×8 (4:2:2), or most commonly 16×16 (4:2:0)." – pree Apr 11 '13 at 23:54
  • 2
    Alas, first link is dead. While an old question, it would be good to have the answer here. – Graham Leggett Aug 10 '20 at 10:55
  • Web archive to the rescue. https://web.archive.org/web/20160821005725/http://wizards-toolkit.org/discourse-server/viewtopic.php?&f=22&t=20333 – Donny V. Dec 09 '20 at 21:44