join_tile_masks

join_tile_masks#

rapidtools.processing.street_tiles.join_tile_masks(tiles: Sequence[tuple[int, int, int]], masks: Sequence[ndarray | None], scores: Sequence[Sequence[float] | None], width: int, height: int, is_pano: bool) → list[tuple[list[tuple[float, float]], float | None]][source]#

Outlines, on the whole frame, of the masks found in its tiles.

Masks that overlap are one object: two tiles show what stands where they overlap, and a mask cut by the edge of one tile continues in the next. An outline that reaches the lower edge of the tiled part of the frame is left out, because the foot of that object is not in it and its distance cannot be read.

Parameters:
  • tiles – The tiles of tile_layout().

  • masks – For every tile, an (n, side, side) array of masks, or None when it has none.

  • scores – For every tile, the confidence of each mask, or None.

  • width – Width of the frame in pixels.

  • height – Height of the frame.

  • is_pano – Whether the frame wraps around.

Returns:

list[tuple[list[tuple[float, float]], float | None]] – One outline per object as (x, y) vertices in normalized frame coordinates, with the highest confidence among the masks it was joined from. An outline across the seam of a panorama has vertices on both sides of it.

Example

>>> import numpy as np
>>> a, b = np.zeros((1, 100, 100), bool), np.zeros((1, 100, 100), bool)
>>> a[0, 40:60, 90:] = True  # cut by the right edge of the first tile
>>> b[0, 40:60, 10:25] = True  # and continued in the second
>>> ((outline, score),) = join_tile_masks(
...     [(0, 0, 100), (80, 0, 100)], [a, b], [[0.9], [0.7]], 180, 100, False)
>>> xs = [round(x * 180) for x, _ in outline]
>>> min(xs), max(xs)
(90, 105)
>>> score
0.9