Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DCT operating on pixel values between -128 to +127

Why DCT (Discrete Cosine Transform) is meant to operate between the pixel values -128 to 127 in JPEG compression?

Why do level offsetting (subtracting by 128) is done on the pixel values before applying DCT on the image

like image 778
Nrupatunga Avatar asked Oct 06 '22 12:10

Nrupatunga


2 Answers

Do you read Wikipedia?

Each 8×8 block of each component (Y, Cb, Cr) is converted to a frequency-domain representation, using a normalized, two-dimensional type-II discrete cosine transform (DCT).

Before computing the DCT of the 8×8 block, its values are shifted from a positive range to one centered around zero. For an 8-bit image, each entry in the original block falls in the range [0, 255]. The midpoint of the range (in this case, the value 128) is subtracted from each entry to produce a data range that is centered around zero, so that the modified range is [-128, 127].

This step reduces the dynamic range requirements in the DCT processing stage that follows. (Aside from the difference in dynamic range within the DCT stage, this step is mathematically equivalent to subtracting 1024 from the DC coefficient after performing the transform – which may be a better way to perform the operation on some architectures since it involves performing only one subtraction rather than 64 of them).

like image 67
ymn Avatar answered Oct 10 '22 02:10

ymn


Here is what I have understood.. Say the level offsetting is not done then if we take the DCT on this matrix the DC value(say X) will be a bigger number since all the pixel values are positive. When the level offsetting is done on the image pixel values, some pixel values will be negative and some will be positive. Later when we take the DCT on the resulting matrix, the DC value(say Y) now will not be a bigger number as it was before i.e., Y < X. So the number of bits required to store this data Y will be less than that required for X.

Thus level offsetting is required and DCT is meant to operate between pixel values -128 to 127

like image 25
Nrupatunga Avatar answered Oct 10 '22 02:10

Nrupatunga