Min_distance parameters of peak_local_max

Hi,
I’m a bit confused by this function argument.
The doc reads :

Peaks are the local maxima in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance).

In the picture below, I scheme a case with 2 crosses as 2 maxima pixels.
Now if I use min_distance = 1 they are indeed separated by 1 pixel, however in the red square of dimensions 2 * min_distance + 1, there is now more than one maxima…
Unless the doc meant, “in a region of 2 * min_distance + 1, centered on the maxima

So what does the function actually returns in this case ?

1 Like

Yes, it is indeed centered on the maximum. It can be inferred from the comment in parentheses but it could be clearer.

Note that this function is a bit buggy and something we aim to improve on:

``````In [6]: image = np.zeros((3, 5))

In [7]: image[1, 1] = 1

In [8]: image[1, 3] = 1

In [9]: image
Out[9]:
array([[0., 0., 0., 0., 0.],
[0., 1., 0., 1., 0.],
[0., 0., 0., 0., 0.]])

In [11]: feature.peak_local_max(image, min_distance=1)
Out[11]:
array([[1, 3],
[1, 1]])

In [12]: feature.peak_local_max(image, min_distance=2)
Out[12]: array([], shape=(0, 2), dtype=int64)

In [13]: image[1, 1] = 2

In [14]: feature.peak_local_max(image, min_distance=2)
Out[14]: array([], shape=(0, 2), dtype=int64)
``````

If you don’t need to use `min_distance`, you can use `morphology.local_maxima` instead, and do your own maximum suppression afterwards. See this issue for more details:

3 Likes