Contour Identification
Python Functions
- actag.contour_identification.convert_contour_list_to_img(contours_list: list, img_shape: tuple[int, int]) ndarray
Visualize a contour list onto an image of the specified shape.
- Parameters:
contours_list (list) – A list of contours to visualize.
img_shape (tuple[int, int]) – The shape of the image to visualize the contours on.
- Returns:
An image with the contours drawn.
- Return type:
np.ndarray
- actag.contour_identification.flood_fill(img: ndarray, row_seed: int, col_seed: int, fill_val: int) ndarray
Fill anything connected to the seeded pixel with the designated fill value.
- Parameters:
img (np.ndarray) – 2D image.
row_seed (int) – The row index of the pixel used to start the fill.
col_seed (int) – The column index of the pixel used to start the fill.
fill_val (int) – The value with which to fill the seeded pixel and its connected neighbors.
- Returns:
The image that has been filled.
- Return type:
np.ndarray
- actag.contour_identification.get_contours(img: ndarray, sonar_params: SonarParams, tag_params: AcTagParams, tag_size_tolerance: float = 0.2, tag_area_tolerance: float = 0.2, min_tag_area_ratio: float = 0.1, reject_black_shapes: bool = True, reject_white_shapes: bool = False, reject_by_tag_size: bool = True, reject_by_area: bool = True) list
Contours are identified using a border following algorithm described in “Border following: new definition gives improved borders”.
In this implementation we iterate through the ‘layers’, or levels in the parenthood heirarchy. So the first layer identifies all of the shapes whose parent contour is the frame of the image. Then the second layer identifies all of the shapes whose parent contour is found in the first layer, and so on. The algorithm terminates when it fails to find any contours in the layer it is working on, or in other words, when the image it is working on is a zero array.
- Parameters:
img (np.ndarray) – the image of which the contours will be found.
sonar_params (SonarParams) – The parameters of the sonar that took the image.
tag_params (AcTagParams) – The parameters of the tag that is being detected.
tag_size_tolerance (float) – The tolerance for rejecting contours that are too long in the range or azimuth axes
tag_area_tolerance (float) – The tolerance for rejecting contours that are too large or too small in pixel area
min_tag_area_ratio (float) – The ratio of the smallest size of a tag when rotated to the full size of the tag
reject_black_shape (bool) – Flag to reject black contours (i.e. outer area is white, inner is black)
reject_white_shapes (bool) – Flag to reject white contours (i.e. outer area is black, inner is white)
reject_by_tag_size (bool) – Flag to reject contours that are too long in range or azimuth axes
reject_by_area (bool) – Flag to reject contours that are too large or too small in pixel area
- Returns:
A list containing all of the image contours.
- Return type:
list
- actag.contour_identification.merge_and_invert_colors(binary_img: ndarray) ndarray
Merge the outermost two layers and invert the colors of the image. This prepare the next layer of the image to be searched for contours.
- Parameters:
binary_img (np.ndarray:) – 2D image.
- Returns:
The merged and inverted image.
- Return type:
np.ndarray
- actag.contour_identification.trace_contour(contour_img: ndarray, searchable_img: ndarray, row_seed: int, col_seed: int, neighbors: ndarray) tuple[ndarray, list, int, list]
From a starting pixel, trace and return the entirety of the contour.
- Parameters:
contour_img (np.ndarray) – Binarized 2D image for this layer.
searchable_img (np.ndarray) – Array to indicate if a given pixel is “searchable”. Pixels part of, or inside of, a contour are marked so that they are not searchable in the current layer.
row_seed (int) – The row index of the starting pixel of the contour.
col_seed (int) – The column index of the starting pixel of the contour.
neighbors (np.ndarray) – Array of the eight-connected neighbors of a pixel.
- Returns:
A tuple containing the searchable image, the contour chain, the number of pixels in the contour, and the min/max pixel values of the contour.
- Return type:
tuple[np.ndarray, list, int, list]
Rust Functions
- actag.rust_impl.get_contours()
Rust equivalent of
actag.contour_identification.get_contours().- Parameters:
img (Vec<Vec<i32>>) – the image of which the contours will be found.
min_range (f64) – Minimum range of the sonar in meters
max_range (f64) – Maximum range of the sonar in meters
horizontal_aperture (f64) – Horizontal aperture of the sonar in radians
tag_size (f64) – Side length of the white square on the inside of the tag in meters
tag_size_tolerance (f64) – The tolerance for rejecting contours that are too long in the range or azimuth axes
tag_area_tolerance (f64) – The tolerance for rejecting contours that are too large or too small in pixel area
min_tag_area_ratio (f64) – The ratio of the smallest size of a tag when rotated to the full size of the tag
reject_black_shape (bool) – Flag to reject black contours (i.e. outer area is white, inner is black)
reject_white_shapes (bool) – Flag to reject white contours (i.e. outer area is black, inner is white)
reject_by_tag_size (bool) – Flag to reject contours that are too long in range or azimuth axes
reject_by_area (bool) – Flag to reject contours that are too large or too small in pixel area
- Returns:
The vector containing all of the image contours.
- Return type:
Vec<Vec<i32>>
- actag.rust_impl.plot_contours()
Visualize a contour list onto an binary image with the specified dimensions.
- Parameters:
contour_list (Vec<Vec<i32>>) – A list of contours to visualize.
img_shape ((usize, usize)) – The shape of the image to plot the contours onto.
- Returns:
An image with the contours drawn.
- Return type:
Vec<Vec<i32>>