# What is the maximum value that can result from a 2D DCT?

Assuming that I have an 8x8 matrix of 8 bit unsigned values and carry out a 2D DCT on them, what is the biggest value that can result from it? This will help be decide how many bits to use. I am aware that the output coefficients are signed.

• well, I think you can solve this yourself. What's the formula of any term of the 2D DCT? – Marcus Müller Sep 6 '17 at 20:49

$$S_{uv} = \frac{1}{4} C_u C_v \sum_{y=0}^7 \sum_{x=0}^7 s_{xy} \cos\frac{(2x+1)u\pi}{16} \cos\frac{(2y+1)v\pi}{16}$$
The argument of the summation is of the magnitude of $s_{xy}$ times two values which are at most 1 (absolute value). So still 8 bits. You are summing $8 \times 8 = 64$ of those values, so $2^6 \times 2^8 = 2^{14}$. But you also divide this by $\frac{1}{4}$ so the maximum value requires 12 bits. You also have to consider that this value is obtained only when u anv v are 0, and in that case $C_u=C_v=\frac{1}{\sqrt{2}}$, so $C_uC_v=\frac{1}{2}$, that is another bit is unneeded. Some other checks are required when only $u=0$ or $v=0$, but overall you will need 11 bits at most.