当前位置:网站首页>Label the mask image not obtained through labelme

Label the mask image not obtained through labelme

2022-06-11 07:51:00 AQ14_

Existing mask Label image

def mask_label(img_shape,mask,label_name_to_value):
	cls = np.zeros(img_shape[:2], dtype=np.int32)
	cls_name='module'
	cls_id = label_name_to_value[cls_name]
	cls[mask] = cls_id
	return cls

labelme Drawing included in mask Image code

def shape_to_mask(img_shape, points, shape_type=None,
                  line_width=10, point_size=5):
    mask = np.zeros(img_shape[:2], dtype=np.uint8)
    mask = PIL.Image.fromarray(mask)
    draw = PIL.ImageDraw.Draw(mask)
	xy = [tuple(point) for point in points]
	assert len(xy) > 2, 'Polygon must have points more than 2'
	draw.polygon(xy=xy, outline=1, fill=1)
	mask = np.array(mask, dtype=bool)
    return mask
原网站

版权声明
本文为[AQ14_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020516592105.html