imageutil.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:nuts-ml 作者: maet3608 项目源码 文件源码
def annotation2mask(image, annotations, pos=255):
    """
    Convert geometric annotation to mask.

    For annotation formats see:
    imageutil.annotation2coords

    >>> import numpy as np
    >>> img = np.zeros((3, 3), dtype='uint8')
    >>> anno = ('point', ((0, 1), (2, 0)))
    >>> annotation2mask(img, anno)
    array([[  0,   0, 255],
           [255,   0,   0],
           [  0,   0,   0]], dtype=uint8)

    :param annotation annotation: Annotation of an image region such as
      point, circle, rect or polyline
    :param int pos: Value to write in mask for regions defined by annotation
    :param numpy array image: Image annotation refers to.
      Returned mask will be of same size.
    :return: Mask with annotation
    :rtype: numpy array
    """
    mask = np.zeros(image.shape[:2], dtype=np.uint8)
    for rr, cc in annotation2coords(image, annotations):
        mask[rr, cc] = pos
    return mask
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号