Search code examples
jpegsamplingsubsampling

Interpreting JPEG Chroma Subsampling read from file


I am trying to find out of which MCU (8x8, 16x8 and 16x16) a pictures is made of. To do this I parse the Start of Frame (SOFn) Marker where the chroma subsampling factors are stored. I have found the following content:

Number of Img components = 3
Component[1]: ID=0x01, Samp Fac=0x22 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y)
Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cb)
Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cr)

I am confused on how to interpret that. Reading this I came to believe that 1x1 stands for 4:4:4 sampling and thus leading to a 8x8 pixel MCU, 2x1 for 4:2:2 -> 16x8 pixel MCU and 2x2 for 4:2:0 -> 16x16 pixl MCU.

Every sampling rate dictates how the components are stored in the entropy coded data and thus leading to the MCU. But now every component (Y, Cb, Cr) has its own subsampling rate.

How do I interpret the date I read from the JPEG marker to judge wich MCU is used through the whole image?


Solution

  • In JPEG the different components are typically sampled differently. This is because the human eye is more perceptive to variations in luminance than color (chromacity).

    In your example, the luminance is sampled in full frequency (as always for JPEG), while both chromaicity components are subsampled 2x2 (or subsampled both horizontally and vertically if you like). This means that for every chroma sample, there is 4 luminance samples.

    Something like (where C = Cb, c = Cr):

    YCcY  YCcY...
    Y  Y  Y  Y... 
    YCcY  YCcY...
    Y  Y  Y  Y... 
    .  .  .  .
    .  .  .  .
    

    (these are pixels, the samples might be stored as YYYYCcYYYYCc... in the stream)

    So, your question: The largest subsampling factor of all the components will decide the MCU size. In your case 16x16.