giant.image_processing.local_maxima

giant.image_processing.local_maxima(data_grid)[source]

This function returns a boolean mask selecting all local maxima from a 2d array.

A local maxima is defined as any value that is greater than or equal to all of the values surrounding it. That is, given:

+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+

value 5 is a local maxima if and only if it is greater than or equal to values 1, 2, 3, 4, 6, 7, 8, 9.

For edge cases, only the valid cells are checked (ie value 1 would be checked against values 2, 4, 5 only).

>>> from giant.image_processing import local_maxima
>>> im = [[0, 1, 2, 20, 1],
...       [5, 2, 1, 3, 1],
...       [0, 1, 2, 10, 1],
...       [1, 2, -1, -2, -5]]
>>> local_maxima(im)
array([[False, False, False,  True, False],
       [ True, False, False, False, False],
       [False, False, False,  True, False],
       [False,  True, False, False, False]], dtype=bool)
Parameters:

data_grid (Sequence[Sequence] | ndarray) – The grid of values to search for local maximas

Returns:

A 2d boolean array with True where the data_grid values are local maximas

Return type:

ndarray