easyidp.cvtools.poly2mask#
- easyidp.cvtools.poly2mask(image_shape, poly_coord, engine='skimage')#
convert vector polygon to raster masks
- 参数:
image_shape (tuple with 2 element) –
小心
it is reversed with numpy index order
(horizontal, vertical) = (width, height)
poly_coord ((n, 2) np.ndarray -> dtype = int or float) –
小心
The xy is reversed with numpy index order
(horizontal, vertical) = (width, height)
engine (str, default "skimage") –
“skimage” or “shapely”; the “pillow” has been deprecated;skimage -skimage.draw.polygon2mask
, the default method;pillow is slight different than “skimage”, deprecated;shapely is almost the same with “skiamge”, but effiency is very slow, not recommended.
- 返回:
mask – the generated binary mask
- 返回类型:
numpy.ndarray
备注
This code is inspired from [1] .
And for the poly_coord, if using shapely engine, it will following this logic for int and float:
- If dtype is int -> view coord as pixel index number
Will + 0.5 to coords (pixel center) as judge point
- if dtype is float -> view coords as real coord
(0,0) will be the left upper corner of pixel square
引用