mask_outlines

Contents

mask_outlines#

rapidtools.processing.street_instances.mask_outlines(mask: ndarray, min_area: float = 0.0002, tolerance: float = 0.002) → list[ndarray][source]#

Outer outlines of a binary mask in normalized image coordinates.

Parameters:
  • mask – (height, width) array; nonzero cells are inside.

  • min_area – Parts smaller than this share of the image are dropped.

  • tolerance – Outlines are simplified to within this distance, in normalized units.

Returns:

list[np.ndarray] – One (n, 2) array of (x, y) vertices per part of the mask, both in [0, 1], largest part first. Holes are not kept.

Example

>>> import numpy as np
>>> mask = np.zeros((50, 100), bool)
>>> mask[10:30, 20:60] = True
>>> (ring,) = mask_outlines(mask)
>>> ring.min(axis=0).round(2).tolist(), ring.max(axis=0).round(2).tolist()
([0.2, 0.2], [0.6, 0.6])