99def vectorize_to_v4_label (
1010 segmentation_map ,
1111 legend : Dict [int , str ],
12- epsilon : Optional [float ] = None ) -> DefaultDict [str , List [dict ]]:
12+ max_num_points : Optional [int ] = 50 ) -> DefaultDict [str , List [dict ]]:
1313 """Converts a segmentation map into polygons.
1414
1515 Given a raster pixel wise array of predictions in `segmentation_map`,
@@ -25,10 +25,8 @@ def vectorize_to_v4_label(
2525 legend: A dictonary mapping pixel values
2626 used in `segmentation_map` to semantic
2727 class names.
28- epsilon: An optional argument, if present
29- controls the amount of path simplification.
30- Start with 1.0 and decrease to 0.01, 0.001.
31- No simplification occurs if absent.
28+ max_num_points: The maximum number of points in the simplified path.
29+ If `None`, then no path simplification is performed.
3230
3331 Returns:
3432 A dictionary suitable for use as a `prediction`
@@ -43,8 +41,12 @@ class names.
4341 if pixel_value in legend and pixel_value is not 0 :
4442 xy_list = polygon ['coordinates' ][0 ]
4543
46- if epsilon :
44+ if max_num_points :
45+ epsilon = 0.001
4746 xy_list = simplify_coords (xy_list , epsilon )
47+ while len (xy_list ) > max_num_points :
48+ epsilon *= 2
49+ xy_list = simplify_coords (xy_list , epsilon )
4850
4951 geometry = []
5052 for point in xy_list :
0 commit comments