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
评论列表
文章目录