function [ MB_out ] = inverse_quantize( frame_mb, MB_size, B_size, Q  )

if (size(frame_mb,3)~=1)
    if (size(frame_mb,1)>=B_size)
    MB_spectrum = mat2cell( frame_mb.*repmat( Q , size(frame_mb,1)/B_size, size(frame_mb,2)/B_size , size(frame_mb,3)),...
        repmat(B_size,1, size(frame_mb,1)/B_size ), repmat(B_size,1, size(frame_mb,2)/B_size ),size(frame_mb,3) );
    else
          MB_spectrum  = mat2cell( frame_mb, size(frame_mb,1), size(frame_mb,1), size(frame_mb,3) );  
    end
else
    
    MB_spectrum = mat2cell( frame_mb.*repmat( Q , size(frame_mb,1)/B_size, size(frame_mb,2)/B_size ),...
        repmat(B_size,1, size(frame_mb,1)/B_size ), repmat(B_size,1, size(frame_mb,2)/B_size ) );
end

for n = 1 : size(MB_spectrum,1)
    for m = 1 : size(MB_spectrum,2)
        act_block = MB_spectrum{n,m};
        for k = 1 : size(frame_mb,3)
            act_block(:,:,k) = idct2(act_block(:,:,k));
        end
        MB_spectrum{n,m} = act_block;
    end
end
MB_out = cell2mat(MB_spectrum);
end

