easyidp.cvtools.poly2mask#

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

convert vector polygon to raster masks

Parameters:
  • image_shape (tuple with 2 element) –

    Caution

    it is reversed with numpy index order

    (horizontal, vertical) = (width, height)

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

    Caution

    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.

Returns:

mask – the generated binary mask

Return type:

numpy.ndarray

Notes

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