Welcome to pycontour’s documentation!¶
The documentation for pycontour is mainly organized by sub-modules.
Representation Transform¶
swap_wh¶
- def swap_wh(np_arr):
“”” Swap row of width and row of height.
“””
np_arr_to_point_list¶
- def np_arr_to_point_list(np_arr):
“”” Convert 2d numpy array to list of points.
“””
point_list_to_np_arr¶
- def point_list_to_np_arr(point_list):
“”” Convert list of point coordinates to numpy 2d array.
“””
cv_cnt_to_np_arr¶
- def cv_cnt_to_np_arr(cv_cnt):
“”” Convert cv2 contour to numpy 2d array ([0]-h, [1]-w).
“””
np_arr_to_cv_cnt¶
- def np_arr_to_cv_cnt(np_arr):
“”” Convert numpy 2d array ([0]-h, [1]-w) to cv2 contour.
“””
np_arr_to_poly¶
- def np_arr_to_poly(np_arr):
“”” Using numpy 2d array ([0]-h, [1]-w) to construct polygon.
“””
point_list_to_poly¶
- def point_list_to_poly(point_list):
“”” Using point list to construct polygon.
“””
bbox_to_poly¶
- def bbox_to_poly(min_w, min_h, max_w, max_h):
“”” Using bounding box to construct polygon.
“””
poly_to_np_arr¶
- def poly_to_np_arr(poly):
“”” Convert shapely Polygon to numpy 2d array ([0]-h, [1]-w).
“””
Contour Transform¶
shift_cnt¶
- def shift_cnt(np_arr, shift_h=None, shift_w=None)::
“”” Shift the position of contour.
“””
rotate_cnt¶
- def rotate_cnt(np_arr, angle):
“”” Rotate contour clockwise by radian angle around contour center
“””
smooth_cnt¶
- def smooth_cnt(np_arr, sigma=5):
“”” Smooth the contour
“””
Contour¶
get_cnt_area¶
- def get_cnt_area(cnt):
“”” Calcualte the number of pixels contour covered.
“””
get_cnt_aspect_ratio¶
- def get_cnt_aspect_ratio(cnt):
“”” Calcualte the aspect ratio of contour.
“””
get_cnt_solidity¶
- def get_cnt_solidity(cnt):
“”” Calcualte the solidity of contour.
“””
Polygon¶
poly_to_valid¶
- def poly_to_valid(poly):
“”” Adjust polygon to be valid if not.
“””
get_poly_area¶
- def get_poly_area(poly):
“”” Calcualte the number of pixels the polygon covered.
“””
get_poly_bounds¶
- def get_poly_bounds(poly):
“”” Find the bounds of the Polygon.
“””
get_poly_hw¶
- def get_poly_hw(poly):
“”” Find height and width of the polygon.
“””
Relation¶
contour_intersects¶
- def contour_intersects(np_arr1, np_arr2):
“”” Determine two contours are intersected or not.
“””
construct_intersection_polygon¶
- def construct_intersection_polygon(np_arr1, np_arr2):
“”” Construct polygon from the intersection part of two contours.
“””
contour_contains¶
- def contour_contains(np_arr1, np_arr2):
“”” Determine if contour of np_arr1 contains contour of np_arr2.
“””
cnt_dice_ratio¶
- def cnt_dice_ratio(cnt1, cnt2, smooth=0.01):
“”” Calculate the dice ratio between two contours.
“””
cnt_jaccard_index¶
- def cnt_jaccard_index(cnt1, cnt2, smooth=0.01):
“”” Calculate the jaccard index between two contours.
“””
point_in_contour¶
- def point_in_contour(np_arr, py, px):
“”” Determine point inside contour or not.
“””