Download (direct link):
3.3.1 Color Space Conversion
In this book, we consider color space conversion from RGB to YCbCr and vice versa only. There are several ways to convert from RGB to YCbCr color space. In this book, we adopt the CCIR (International Radio Consultative Committee) Recommendation 601-1. This is the typical method for color conversion used in baseline JPEG compression. According to the CCIR 601-1 Recommendation, the transformation from RGB to YCbCr is done based on the following mathematical expression:
Color space conversion from RGB to YCbCr using the above transformation may result in negative numbers for Cb and Cr, while Y is always positive. In order to represent Cb and Cr in unsigned 8-bit integers, they are level shifted by adding 128 to each sample followed by rounding and saturating the value in the range [0, 255]. Hence the above transformation can be expressed as
0.299000 0.587000 0.114000 -0.168736 -0.331264 0.500002 0.500000 -0.418688 -0.081312
/ Y \ / 0.29900 0.58700 0.11400 \ / R \ / 0 \ C£> = -0.16874 -0.33126 0.50000 G + 128 \ Cr J \ 0.50000 -0.41869 -0.08131 / \ B j \ 128 /
BASELINE JPEG COMPRESSION 61
in order to produce 8-bit unsigned integers for each of the components in the YCbCr domain. Accordingly, the inverse transformation from YCbCr to RGB is done as
/ R \ / 1.0 0.0 1.40210 \ / Y \ / 0 \
G = 1.0 -0.34414 -0.71414 C6 - 128 \ B ) \ 1.0 1.77180 0.0 ) \Cr J \ 128 /
After the color space conversion, most of the spatial information of the image is contained in the luminance component (Y). The chrominance components (Cb and Cr) contain mostly redundant color information and we lose little information by subsampling these components both horizontally and/or vertically. We can subsample the chrominance components by simply throwing away every other sample in each row and/or in each column if desired. If we subsample the redundant chrominance components both horizontally and vertically, the amount of data required to represent the color image is reduced to half because the size of each chrominance component (Cb and Cr) is one-fourth of the original size. This color format is called the 4:2:0 color subsampling format. Baseline JPEG also supports 4:2:2 and 4:4:4 color formats. Each chrominance component, in 4:2:2 color format, has the same vertical resolution as the luminance component, but the horizontal resolution is halved by dropping alternate samples in each row. In 4:4:4 format, both the chrominance components Cb and Cr have identical vertical and horizontal resolution as the luminance component. Hence no subsampling is done in 4:4:4 format. The subsampling operation to generate in 4:2:0 or 4:2:2 color format is the first lossy step. For a grayscale image there is only one component and obviously no color transformation is required.
3.3.2 Source Image Data Arrangement
In the previous section, we have seen that the dimension of each of the color components Y, Cb, and Cr could be different depending on the color subsampling format. Each color component is divided into 8x8 nonoverlapping blocks, and we can form what is called a minimum coded unit (MCU) in JPEG by selecting one or more data blocks from each of the color components. The standard defines the arrangement of the data blocks in interleaved or noninterleaved scanning order of the color components. In noninterleaved scan, the data blocks in each color component are stored and processed separately in raster scan order, left-to-right and top-to-bottom. In interleaved order, data blocks from all the color components appear in each MCU. Definition of the MCUs for 4:4:4, 4:2:2, and 4:2:0 formats of YCbCr images in interleaved scan is shown in Figure 3.2.
Each dot in Figure 3.2 represents a 8 x 8 data block. In 4:4:4 format interleaved scan, each MCU consists of a data block from each of the Y, Cb, and Cr components as shown in Figure 3.2(a). The order of processing these blocks is in the scan order from left to right and top to bottom. For example,
62 JPEG: STILL IMAGE COMPRESSION STANDARD
Fig. 3.2 (a) YCbCr 4:4:4, (b) YCbCr 4:2:2, (c) YCbCr 4:2:0.
the first MCU consists of the first data blocks Y00 from the Y component followed by the first data blocks CbOO from the Cb component followed by CrOO from the Cr component as shown in Figure 3.2(a). The next MCU consists of Y01, CbOl and CrOl respectively. After all the MCUs consisting of the 8x8 data blocks from the first row, as shown in Figure 3.2(a), are encoded the second row of 8 x 8 blocks are scanned in the similar fashion. This procedure is continued until the last 8x8 block in the raster scan is encoded. In 4:2:2 format, each MCU consists of a 2 x 2 unit of four data blocks from the Y component, a 2 x 1 unit of two data blocks from each of the Cb and Cr components, and the corresponding order of processing is shown in Figure 3.2(b). In 4:2:0 format, each MCU consists of 2 x 2 units of four data blocks from the Y component, one from each of the Cb and Cr components, and the corresponding order of processing is shown in Figure 3.2(c).