easyidp.cvtools.poly2mask

easyidp.cvtools.poly2mask(image_shape, poly_coord, engine='skimage')

将矢量多边形转换为栅格掩膜

参数:
  • image_shape (tuple with 2 element) --

    小心

    它与 numpy 索引顺序相反

    (水平, 垂直) = (宽度, 高度)

  • poly_coord ((n, 2) np.ndarray -> dtype = int or float) --

    小心

    xy 与 numpy 索引顺序相反

    (水平, 垂直) = (宽度, 高度)

  • engine (str, default "skimage") --

    "skimage" only; the "pillow" and "shapely" has been deprecated;
    skimage - skimage.draw.polygon2mask,默认方法;
    pillow 与 "skimage" 略有不同,已弃用;
    shapely is almost the same with "skiamge", but effiency is very slow, deprecated.

返回:

mask -- 生成的二进制掩膜

返回类型:

numpy.ndarray

备注

此代码受 [1] 启发。

对于 poly_coord,如果使用 shapely 引擎,它将遵循以下整数和浮点数的逻辑:

如果数据类型是 int -> 将坐标视为像素索引号

将 + 0.5 到坐标(像素中心)作为判断点

如果数据类型是 float -> 将坐标视为真实坐标

(0,0) 将是像素方块的左上角