def polygons_to_bitmask(polygons, height, width):
    """converts a set of polygons into a bitmask """
    if any(len(p) <= 4 for p in polygons):
        polygons = [p for p in polygons if len(p) > 4]
    if len(polygons) == 0:
        return np.zeros((height, width)).astype(int)

    rles = mask_util.frPyObjects(polygons, height, width)
    rle = mask_util.merge(rles)
    return mask_util.decode(rle).astype(int)
converts a set of polygons into a bitmask 
contrib/QualityInspector/qinspector/utils/visualizer.py