Professional Documents
Culture Documents
L. Karlsson
L. Karlsson ()
1 / 18
Example
(a) Original
(b) Low
(c) High
L. Karlsson ()
Part I Images
L. Karlsson ()
3 / 18
Colors
RGB: pRGB r = g , b
where r , g , b are the red, green, and blue components of the pixel p. YCbCr: pYCbCr y = cb , cr
where y is the luminance, and cb and cr are the chroma components. RGB and YCbCr are related by 0.2990 0.5870 0.1140 0 pYCbCr = 0.1687 0.3313 0.5000 pRGB + 128 . 0.5000 0.4187 0.0813 128
L. Karlsson () Discrete Cosine Transform and JPEG 4 / 18
Images
L. Karlsson ()
5 / 18
Numerical types
The function image expects a matrix of the uint8 type. Floating point numbers in MATLAB are of type double. Convert to specic type using the type name as a function.
To double: B = double(A). To uint8: A = uint8(B). Values outside 0255 are forced to the nearest bound.
Expressions with mixed types often cause errors. Note that uint8(2) - uint8(5) is 0 of type uint8. Convert to double before subtracting if you want the result -3.
L. Karlsson ()
6 / 18
L. Karlsson ()
7 / 18
L. Karlsson ()
8 / 18
1-D DCT
Component-wise form
xi cos
i =1
(2i 1)(u 1) 2n
1/ 2 if u = 1, C (u ) 1 otherwise.
L. Karlsson ()
9 / 18
1-D DCT
Matrix form
Input: vector x Rn . Output: vector y Rn . Transform in matrix form: y = Z x, where Z Rnn and zij = C (i ) In MATLAB: Z = dctmtx(n). Z is orthogonal, i.e., Z 1 = Z T . 2 cos n (2j 1)(i 1) 2n .
L. Karlsson ()
10 / 18
2-D DCT
(Forward) DCT: Input: matrix X Rnn . Output: matrix Y Rnn . Transform in matrix form: Y = ZXZ T . In MATLAB: Y = dct2(X). Inverse DCT: Input: matrix Y Rnn . Output: matrix X Rnn . Transform in matrix form: X = Z T YZ . In MATLAB: X = idct2(Y).
L. Karlsson () Discrete Cosine Transform and JPEG 11 / 18
L. Karlsson ()
12 / 18
L. Karlsson ()
13 / 18
JPEG
Joint Photographic Experts Group (JPEG) A continuous tone image compression standard. Builds on the 2-D DCT of size 8 8. Uses YCbCr images, treated as three separate images.
L. Karlsson ()
14 / 18
Convert the image to YCbCr. Partition the image into blocks of size 8 8. For each component of each block:
Apply the 2-D DCT. Quantize (discards information).
Encode (compresses).
L. Karlsson ()
15 / 18
Decode (decompresses). Partition the image into blocks of size 8 8. For each component of each block:
Dequantize. Apply the 2-D inverse DCT.
L. Karlsson ()
16 / 18
Quantization
Input: matrix X Rnn and quantization table Q Znn . Output: quantized matrix Y Znn . Transformation in component-wise form: yij = round(xij /qij ).
L. Karlsson ()
17 / 18
Dequantization
Input: quantized matrix Y Znn and quantization table Q Znn . Output: dequantized matrix X Znn . Transformation in component-wise form: xij = yij qij .
L. Karlsson ()
18 / 18