Return to Digital Photography Articles

JPEG Minimum Coded Unit (MCU) and Partial MCU

This page should gives some background on how JPEG images are actually defined by 8x8 pixel blocks called the Minimum Coded Unit. This article should help one understand what happens with lossless rotation on odd-sized images.

The breakdown of an image into MCUs

Every JPEG image is actually stored as a series of compressed image tiles that are usually only 8x8 pixels in size. The proper name for one of these tiles is the MCU or Minimum Coded Unit. When one refers to image blocking artifacts, they are really talking about visual discontinuities observed between one or more of these tiles. You can see the edges or boundaries of these tiles in JPEG images that have been compressed at a very low quality.

JPEG Image   JPEG Image at Low Quality
 

The images below show the 8x8 boundaries of the MCU tiles
 

If you look carefully at the low-quality JPEG image, you will notice some of the boundaries of the MCU, as you will see abrupt changes in color and / or intensity. This is because each of these MCU tiles is compressed separately and different amounts of information is discarded from each tile.

Demonstrating the MCU boundaries

The Minimum Coded Unit size for JPEG images is usually 8x8, 16x8 or 16x16 pixels in size. The variations here (more specifically 16x8 and 16x16) are due to an optimization called chroma subsampling.

For JPEG compression and decompression algorithms to work, an image must be represented by an integer number of complete MCUs. In other words, the X and Y dimensions typically need to be a multiple of 8 pixels. Therefore, an image that is sized 501 x 375 must be first changed into an image sized 504 x 376 before it can be compressed. In this example, 501 = 62 horizontal MCUs + 3 extra pixels and 375 is 46 vertical MCUs + 1 extra pixel.

Partial MCU and Odd-sized JPEG images

In the case where there are not enough pixels in a row or column to complete a full tile, a partial MCU is used. A partial MCU is automatically extended to be the size of a full MCU but then the overall image dimensions are used to indicate where to cut off the extra later. This extension is generally done by repeating the last pixel of the row or column as necessary.

For the purposes of this discussion, I refer to images that contain partial MCU as an odd-sized image. In other words, if an image's overall dimensions are not a multiple of 8x8, then it is likely to contain partial MCU and therefore be termed an odd-sized image.

For more information about partial minimum coded units and how they affect image rotation, please see: Lossless rotation & Partial MCU and Digicams and Lossless Rotation.

 


Reader's Comments:

Please leave your comments or suggestions below!
2008-03-11rani
 it was very useful na di think it helped in deoding jpeg image files
 Great!
2007-12-15dave
 Thanks for the article. How can it be determined (for example, programmatically) the dimensions of the MCU for a particular jpg file.
 The best way is to search for the JFIF SOF0 marker (0xFFC0), and about 9 bytes later you will find a list of entries, one per component that indicate the sampling factor. With a byte sequence of 0x 01 22 00 02 11 01 03 11 01, you can interpret this as:

CompChanHex ValuesIndSFQTbl
1Yx012200012200
2Cbx021101021101
3Crx031101031101
In the above, you want to look for the SF (Sampling Factor) values. It actually tells you the number of entries per MCU of that channel (in both Horizontal and Vertical dimensions). Thus, for the above, we see that Y appears 4 times per MCU (2x2) before each of the chrominance components.

To get the dimension, multiply this by 8x8 pixels for each block. So we end up with a 16x16 pixel MCU. Hope that is helpful!
2007-12-06Vijay
 Good, to-the-point introduction to MCUs.
2007-06-05vine
 very informative article, very well explained.
 
2007-05-31Manish Kumar
 I find that usually it use 8x8 MCU. Which applications do we use 16x16 or 16x8?
 Images without chroma subsampling generally have an 8x8 MCU. With chroma subsampling on low-end digital cameras (4:2:0 or 2x2), we'll see 16x16, while most other digital cameras (4:2:2 or 2x1) we'll see 16x8.
2007-03-27francis
 Very good, I'm learning for my test and it helped me a lot! Thx
2007-03-09Ray
 Hi there
You explain so well on JPEG MCU,
I learn a lot from it, THANKS !!!

However, I got a question here

Is it necessary to define MCU?
why don't we just apply DCT on the whole image?
I guess i miss something in the middle.

Thanks in advance ,
peace
Ray
 Performing the DCT transform is a computationally difficult task. By breaking the original image down into smaller blocks, the calculation can be dealt with much more easily. Plus, it allows decoders or encoders to reduce the amount of image information that they need to keep in memory at one time. Some algorithms use larger blocks, such as 16x16 (some forms of MPEG compression), which helps compress larger regions of similar color, but that's about as large a block size as you'll find.

By using a much larger block size (or the full image size!), you would not easily be able to achieve the same compression quality.

In hardware implementations, the breaking down of the image into blocks has the added advantage of enabling the encoder or decoder to work on several blocks in parallel, thereby increasing compression performance significantly.
2007-01-11Ameen
 Hi,
Its really good explanation, One can easily understand about MCU.
-Ameen
2006-07-30mark
 did you know wikipedia does not have an article on MCU? have you considered submitting your article to wikipedia as i think it is an excellent explanation.
 Thanks for the comment! You're right -- I am surprised to see no definition there. I'll look into it, as it may help others as a starting point. Thx, Cal.
 
2006-07-17chunchun
 Good. It is esay to be understood.
2006-02-20natasha
 hi,

really interesting and informative stuff about jpeg. learnt quite a bit.
cheers,
natasha

 


Leave a comment or suggestion for this page:

(Never Shown - Optional, if you want a reply)
 

NOTE: I am out of the country for several months (in India), so comments will be held and only posted infrequently. Thanks!

13 users online