pair_coordinates¶
- pair_coordinates(set_a, set_b, radius)[source]¶
Find optimal unique pairing between two sets of coordinates.
This function uses the Munkres or Kuhn-Munkres algorithm behind the scene to find the most optimal unique pairing when pairing points in set B against points in set A, using Euclidean distance as the cost function.
- Parameters:
set_a (np.ndarray) – An array of shape Nx2 contains the of XY coordinate of N different points.
set_b (np.ndarray) – An array of shape Mx2 contains the of XY coordinate of M different points.
radius (float) – Valid area around a point in set A to consider a given coordinate in set B a candidate for matching.
- Returns:
numpy.ndarray- Pairing:An array of shape Kx2, each item in K contains indices where point at index [0] in set A paired with point in set B at index [1].
numpy.ndarray- Unpaired A:Indices of unpaired points in set A.
numpy.ndarray- Unpaired B:Indices of unpaired points in set B.
- Return type:
Examples
>>> from tiatoolbox.utils.metrics import pair_coordinates >>> # Generate two random example sets; replace with your own data >>> import numpy as np >>> np.random.seed(6) >>> set_a_num_points = np.random.randint(low=10, high=30) >>> set_b_num_points = np.random.randint(low=10, high=30) >>> set_a = np.random.randint(low=0, high=25, size=(set_a_num_points, 2)) >>> set_b = np.random.randint(low=0, high=25, size=(set_b_num_points, 2)) >>> radius = 2.0 >>> # Example usage of pair_coordinates >>> pairing, unpaired_a, unpaired_b = pair_coordinates(set_a, set_b, radius)