quickpaver.binary_dilation#

quickpaver.binary_dilation(seed_mask: ndarray[tuple[Any, ...], dtype[bool]], domain_mask: ndarray[tuple[Any, ...], dtype[bool]], iterations: int = 1) ndarray[tuple[Any, ...], dtype[bool]][source]#

Dilate a 2D boolean array within a constrained domain.

The dilation uses 4-connectivity, meaning that each True cell expands to its direct horizontal and vertical neighbours only. Diagonal neighbours are not included.

After each dilation step, cells outside domain_mask are forced to False. This ensures that the dilated region never grows outside the allowed domain.

Parameters:
  • seed_mask (NDArrayBool) – Initial 2D boolean array to dilate. Cells equal to True are used as dilation seeds.

  • domain_mask (NDArrayBool) – Boolean mask defining where dilation is allowed. Cells equal to True belong to the allowed domain. Cells equal to False are excluded and are forced to remain False in the output.

  • iterations (int, optional) – Number of dilation iterations to apply, by default 1. Each iteration expands the current True region by one cell in the four cardinal directions within domain_mask.

Returns:

Dilated 2D boolean array with the same shape as seed_mask. The result is always False outside domain_mask.

Return type:

NDArrayBool

Raises:
  • ValueError – If seed_mask and domain_mask do not have the same shape.

  • ValueError – If iterations is negative.