 # Min_distance parameters of peak_local_max

Hi,
I’m a bit confused by this function argument.

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 : image = np.zeros((3, 5))

In : image[1, 1] = 1

In : image[1, 3] = 1

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

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

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

In : image[1, 1] = 2

In : feature.peak_local_max(image, min_distance=2)
Out: 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