JPEG Minimum Coded Unit (MCU) and Partial MCU

来源:互联网 发布:数据的标准化处理方法 编辑:程序博客网 时间:2024/05/18 16:38

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 8x816x8 or 16x16 pixels in size. The variations here (more specifically16x8 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!
2009-08-19Chiang Thank you ! This article is very informative and it help me a lot when I was trying to read IJG source codes...2009-03-26sandy First of all thanks for the MCU explanation. 
I have a question about the luma (Y) and two chrominance (UV) components, how they are related to MCU? Each YUV component will have one MCU each? How can we find the total number of MCU in image corresponding to luma (Y) and two chrominance (UV) components.2009-03-10termostat I have one more question about getting the MCU data from the stream. I was looking all over the internet but I can't find any usable informations on how to decode the jpg scan data. First of all I need to get the RLC-coded data of the first MCU. I know that this data are Huffman encoded and I know that the first information in the scan should be the first MCU's DC + 63 AC values (RLC-coded). But I can't find the way to decode them.
I have all the informations extracted from the jpg header and now I would need to know what should I do. I mean "You should read the first bit from the stream and than...".
Could you please help me or give me some pages where to find this informations ? Thanks. The best source of this information is to have a read through the ITU-T spec which is freely available on the web, and then experiment from there to get your decoder working. There are some examples of source code for decoders elsewhere, but you'll get a much firmer understanding by developing your own from the spec. Besides, some of these are complicated greatly by attempts to incorporate performance improvements into the code. Good luck!2009-03-09termostat I have allmost the same question as Mark. If there are no tags for MCU, how do you find out the MCU length ? How can I find out how many bytes will the MCU have in the data stream ? Unfortunately, you will need to perform the huffman decoding in order to find out the individual MCU boundaries. The boundaries can occur on any bit alignment in the data stream (not byte).2009-01-19Mark How do you find the beginning and end of each MCU in the data stream? Is there a tag or a marker? Or are they encoded in a standard length? Generally, no. The JPEG bitstream has nearly all redundancy removed, which makes it very hard to delineate the boundaries of MCUs. However, some digital cameras do take advantage of the Restart markers, which may appear every X MCUs (eg. every 4 MCUs). You can use these to regain position, but even then they only reflect a position in sequence 10 markers long, so there is no absolute positioning.2008-07-22kinki Thank you for your information!
I have a question, if a mcu is equal to a block, i can use a block instead of mcu ,what's the mcu existing for? Is there other function on mcu?
Thank you! The MCU is used in the JPEG compression format to help keep all of the sub-sampled image components together. If there is no chroma subsampling, then the MCU can be treated somewhat similarly to a block.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 ValuesIndSFQTbl1Yx0122000122002Cbx0211010211013Crx031101031101In 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! Thx2007-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.
-Ameen2006-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

原创粉丝点击