Skip to content

polygons

get_reduced_coords(coords, angle_th, distance_th)

Given polygon vertices coordinates, deletes those that are too close or that form a too small angle.

Parameters:

Name Type Description Default
coords NDArray[Any, 2, Number]

array of coordinates.

required
angle_th float

minimum angle (in degrees) formed by 3 consecutives vertices. If the angle is too small, the middle vertex will be deleted.

required
distance_th float

minimum distance between vertices. If 2 consecutive sides of the polygon are too small, the middle vertex will be deleted.

required

Returns:

Type Description
NDArray[Any, 2, int]

Array of polygon coordinates with small and flat sides pruned.

hovernet_to_wkt(infile, outfile, slide_height=None)

Take a hovernet json output file and convert it to a wkt file. Optionally convert coordinates to cytomine format.

Parameters:

Name Type Description Default
infile PathLike

path to input hovernet json file.

required
outfile PathLike

path to output wkt file.

required
slide_height Optional[int]

height of the slide on which hovernet was used. If given, coordinates will be converted to cytomine format (y = slide_height - y).

None

mask_to_polygons_layer(mask, angle_th=2, distance_th=3)

Convert mask array into :class:shapely.geometry.MultiPolygon.

Parameters:

Name Type Description Default
mask NDBoolMask

input mask array.

required

Returns:

Type Description
MultiPolygon

class:shapely.geometry.MultiPolygon where polygons are extracted from

MultiPolygon

positive areas in the mask.

reduce_polygon(polygon, angle_th=0, distance_th=0)

Given a :class:shapely.geometry.Polygon, delete vertices that create small or flat sides on the interior and on the exterior.

Parameters:

Name Type Description Default
polygon Polygon

input polygon.

required
angle_th float

minimum angle (in degrees) formed by 3 consecutives vertices. If the angle is too small, the middle vertex will be deleted.

0
distance_th float

minimum distance between vertices. If 2 consecutive sides of the polygon are too small, the middle vertex will be deleted.

0

Returns:

Type Description
Polygon

Reduced polygon.