Chinaunix首页 | 论坛 | 博客
  • 博客访问: 823202
  • 博文数量: 168
  • 博客积分: 5431
  • 博客等级: 大校
  • 技术积分: 1560
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-22 11:56
文章存档

2015年(2)

2014年(1)

2013年(12)

2012年(12)

2011年(15)

2010年(5)

2009年(16)

2008年(41)

2007年(64)

分类: C/C++

2007-11-20 18:50:49

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 .

For 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 .







JPEG Chroma Subsampling

What is Chroma Subsampling?

The JPEG (JFIF) compressed file format can produce significant reductions in file size through lossy compression. The techniques used to achieve these levels of take advantage of the limitations of the human eye. The compression algorithm saves space by discarding additional image information / detail that may not be as noticeable to the human observer.

It is widely known that we are much more sensitive to changes in luminance (brightness) than we are to chrominance (color) differences. Because of this, the JPEG format can discard a lot more color information than luminance in the compression process. To facilitate the different compression requirements of the two "channels" of image information, the JPEG file format translates 8-bit RGB data (Red, Green, Blue) into 8-bit YCbCr data (Luminance, Chroma Blue, Chroma Red). Now, with the brightness seperated into a separate data channel, it is much easier to change the compression algorithm used for one channel versus the others.

Chroma subsampling is the process whereby the color information in the image is sampled at a lower resolution than the original. The images below show various types of chroma subsampling (from 1x1 to 2x2) and the effect it has on reducing the color information. Pay special attention to the horizontal and vertical stripes.

1x1 (No Subsampling)   2x1 (Subsampling)
 
 
1x2 (Subsampling)   2x2 (Subsampling)
 

 

In the above series, a series of red and blue stripes were drawn with exactly the same Y value (after conversion from RGB to YCbCr) or intensity. When the JPEG compression algorithm performs the chroma subsampling step, it averages out the color information across pairs of pixel, but still preserves the luminance. By choosing RGB values for Red (RGB=97,0,0) and Blue (RGB=0,0,255) that have the same converted Y (luminance component), the resulting stripes will disappear (after "averaging"). Note that the red phosphors are significantly "brighter" than the blue phosphors given the same input stimulation (RGB value).

You can also see the more unpleasant artifacts due to chroma subsampling in regions of significant color changes in adjacent pixels. This is particularly noticeable on the green circle.

Digital Cameras and Chroma Subsampling

Most digital SLR cameras use 2x1 chroma sub-sampling, while some point and shoot digicams use 2x2. The Sigma / Foveon dSLR cameras are one of the few that don't do any chroma subsampling. The color channels from a typical 6 megapixel image (3072x2048 pixels) is first converted into a 3 megapixel image (1536x2048 pixels). In the case of 2x1 (4:2:2) chroma subsampling -- only one for every 2 pixels is used in the horizontal direction, but every pixel in the vertical direction is retained. Some graphics programs (such as Photoshop) often use 2x2 (4:2:0) chroma subsampling, which would further reduce the color information to 1536x1024 pixels.

With the reduction in color "detail", one has less information to compress, resulting in a smaller JPEG file. When it comes time to display the compressed JPEG, the compressed color channel information is uncompressed and then duplicated (doubled) across the adjacent pixels before being merged with the luminance channel for display.

The existence of chroma subsampling in JPEG compression also explains why one can achieve better compression ratios (ratio between original file size and compressed file size) with color photos than with grayscale photos. With chroma subsampling, one gets better compression out of the chrominance channels than the luminance channel. The overall compression ratio for a color photo is therefore somewhere between the two ratios. As a grayscale image has no color information to discard, the overall compression ratio is dictated purely by the lower luminance compression ratio.

Various levels of YCbCr subsampling:

  • 4:4:4 - The resolution of chrominance information (Cb & Cr) is preserved at the same rate as the luminance (Y) information. Also known as 1x1 (or subsampling disabled).
  • 4:2:2 - Half of the horizontal resolution in the chrominance is dropped (Cb & Cr), while the full resolution is retained in the vertical direction, with respect to the luminance. This is also known as 2x1 chroma subsampling, and is quite common for digital cameras.
  • 4:1:1 - Only a quarter of the chrominance information is preserved in the horizontal direction with respect to the luminance information. I don't think this format is nearly as common as the other variations.
  • 4:2:0 - With respect to the information in the luminance channel (Y), the chrominance resolution in both the horizontal and vertical directions is cut in half. This form is also known as 2x2 chroma subsampling.

Steps in JPEG Compression Chroma Subsampling

In order for a JPEG Encoder to take advantage of the file size savings through chroma subsampling, it performs the following basic steps:

  • from RGB to YCbCr
  • For each component Cb and Cr: If horizontal chroma subsampling is specified, output Cb and Cr channels are generated from the average of each adjacent pairs of pixels in the horizontal direction. Similar process for vertical subsampling. In each case, the output channel resolution is halved.
  • For the luminance component, Y, the output channel is identical to the input, irrespective of the chroma subsampling configuration.
  • Remaining steps. But, the SOF0 (Baseline DCT) JPEG marker will now show that components 2 and 3 have a sampling factor other than 1x1.

Please see the relevant section in the page for more details on how the different subsampled channels are encoded in a JPEG file.

When is Chroma Subsampling is bad

The fact that JPEG chroma subsampling relies on the limitations of the human eye means that it is not a particularly good mechanism for compressing images used by other "sensors" (such as in the medical field, etc.), where the chrominance may be equally as important as the luminance.

Photoshop Quality and subsampling:

As an aside, note that Photoshop CS2 uses different chroma subsampling levels depending on the Save JPEG Quality settings:

  • Photoshop Save As Quality 0-6 - 2x2 Chroma Subsampling
  • Photoshop Save As Quality 7-12 - 1x1 No Chroma Subsampling
  • Photoshop Save For Web Quality 0-50 - 2x2 Chroma Subsampling
  • Photoshop Save For Web Quality 51-100 - 1x1 No Chroma Subsampling

阅读(2926) | 评论(0) | 转发(0) |
0

上一篇:媒体类

下一篇:debian resources

给主人留下些什么吧!~~