function [ frame_quantized ] = quantize( frame_mb, MB_size, B_size, Q  )

if ((size(frame_mb,3))~=1)
    if (size(frame_mb,1)>=B_size)
        frame_DCT = mat2cell( ...
            frame_mb, 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
        frame_DCT = mat2cell( frame_mb, size(frame_mb,1), size(frame_mb,1), size(frame_mb,3) );
    end
else
    frame_DCT = mat2cell( frame_mb, 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(frame_DCT,1)
    for m = 1 : size(frame_DCT,2)
        act_block = frame_DCT{n,m};
        for k = 1 : size(act_block,3)
            act_block(:,:,k) = dct2(act_block(:,:,k));
        end
        frame_DCT{n,m} = act_block;
    end
end
frame_quantized = round(  cell2mat(frame_DCT)./repmat( Q , size(frame_mb,1)/B_size, size(frame_mb,2)/B_size , size(frame_mb,3)) );


end

