function spectrum = EQA3YM_dequantizer( quant_spectrum, QF )
% Dequantize DCT spectrum of an image using precomputed quantizer tables

lumi = [  16 11 10 16 24 40 51 61 ...
          12 12 14 19 26 58 60 55 ...
          14 13 16 24 40 57 69 56 ...
          14 17 22 29 51 87 80 62 ...
          18 22 37 56 68 109 103 77 ...
          24 35 55 64 81 104 113 92 ...
          49 64 78 87 103 121 120 101 ...
          72 92 95 98 112 100 103 99] ...
      * QF;
      
chromi = [17 18 24 47 99 99 99 99 ...
          18 21 26 66 99 99 99 99 ...
          24 26 56 99 99 99 99 99 ...
          47 66 99 99 99 99 99 99 ...
          99 99 99 99 99 99 99 99 ...
          99 99 99 99 99 99 99 99 ...
          99 99 99 99 99 99 99 99 ...
          99 99 99 99 99 99 99 99] ...
      * QF;

% Vectorize blocks to dequantize them together
Y_values = im2col(quant_spectrum(:,:,1), [8 8], 'distinct');
Cb_values = im2col(quant_spectrum(:,:,2), [8 8], 'distinct');
Cr_values = im2col(quant_spectrum(:,:,3), [8 8], 'distinct');

% Doing dequantization
Y_dequant = bsxfun(@times, Y_values, lumi');
Cb_dequant = bsxfun(@times, Cb_values, chromi');
Cr_dequant = bsxfun(@times, Cr_values, chromi');

% Reconstruct blocks from vectors
[ X, Y, C ] = size(quant_spectrum);
spectrum = zeros([ X, Y, C ]);
spectrum(:,:,1) = col2im(Y_dequant, [8 8], [ X Y ], 'distinct');
spectrum(:,:,2) = col2im(Cb_dequant, [8 8], [ X Y ], 'distinct');
spectrum(:,:,3) = col2im(Cr_dequant, [8 8], [ X Y ], 'distinct');

end

