# A question about quantization and dequantization calculations

Suppose we have a 2x2 image as follows: What does each dequantised image look like after it has first been quantised to 7, 4 and 2 bits respectively?

I solve this question by initially quantising as follows.

1. Into 7 bits : 8 bits - 7 bits = 1 bit and 2 to the power of 1 is 2 so, 232 / 2 = 116, 127 / 2 = 63, 169 / 2 = 84 and 27 / 2 = 13. Therefore, we have: 1. Into 4 bits: 8 bits - 4 bits = 4 bits and 2 to the power of 4 equals 16. Thus, 232/16 = 14, 127 / 16 = 7, 169 / 16 = 10, 27 / 16 = 1. 1. Into 2 bits: 8 bits - 2 bits = 6 bits and 2 to the power of 6 is 128 so, 232 / 128 = 1, 127 / 128 = 0, 169 / 128 = 1 and 27 / 128 = 0 hence, we have: Now, to dequantise the results we simply multiply each cell value by the number we initially used for quantisation. The above matrices will be as follows respectively:

Are all steps in my solution correct, if not where should be modified?

EDIT

According to what @Hilmar detected, 2 to the power of 6 is 64 and the quantisation into 2 bits should be changed to: 232 / 64 = 3, 127 / 64 = 1, 169 / 64 = 2 and 27 / 64 = 0 hence, we have: There are a couple of ways to "quantize/dequantize" integer data. This should be specified to avoid different results. You have used the version:

$$I_Q = \Delta\left\lfloor I/\Delta \right\rfloor$$

with $$\Delta = 2^{8-b}$$ ($$b$$ is the intermediate bit number) and your results seem fine with that choice. One other possible choice (better preserving bright tones) is: $$I_Q = \Delta\left\lceil (I+1)/\Delta \right\rceil -1$$

Some others preserve the range, etc.

Don't hesitate to clearly state your quantization scheme, as it will be more precise than the inexact computation of rounding 127 / 128 = 0.

Here is a small Matlab code to recover the results:

B = 8; % Original bit-depth
bList = [7,4,2]; % quantized bit-depth
I = [232,127;169,27];
for b = bList
Iq = 2^(8-b)*floor(I/2^(8-b)); % Quantized/Dequantized image
disp(Iq)
end


giving the arrays:

$$\begin{array}{rr} 232 & 126\\ 168 & 26 \end{array}$$

$$\begin{array}{rr} 224 & 112\\ 160 & 16 \end{array}$$

$$\begin{array}{rr} 192 & 64\\ 128 & 0 \end{array}$$

• Thank you. Apart from the quantization scheme, is the de-quantisatiopn process correct?
– plpm
Jun 5, 2021 at 23:23
• I have added some details, ok for 8-bit depth and the basic quantization Jun 6, 2021 at 20:12
• Thank you very much.
– plpm
Jun 7, 2021 at 17:56

Are all steps in my solution correct,

No. Your 2 bit quantizer is clearly wrong. $$2^6 = 64$$ and not 128.

if not where should be modified?

As Laurent Duval has pointed out, that depends a lot on the specific choice of your quantizer. What are your quantization steps, do you round or truncate, how do manage "out of bound" conditions, etc.

• Thank you. You are right. I edit the question. How about the de-quantisation, is it correct?
– plpm
Jun 5, 2021 at 23:25
• We cannot answer this until you define your quantization and de-quantization process. There is more than one "correct" answer. Jun 6, 2021 at 23:34