使用 ndimage.maximum_filter 和 skimage.peak_local_max 查找图像峰值

Finding image peaks using ndimage.maximum_filter and skimage.peak_local_max

我试图找到给定图像的一些相对最大值。我知道有两种可能的方法,第一种是使用 scipy.ndimage.maximum_filter() ,第二种是使用 skimage.feature.peak_local_max().

为了比较这两种方法,我修改了 skimage shown here 中的示例,以便比较找到的峰。

from scipy import ndimage as ndi
import matplotlib.pyplot as plt
from skimage.feature import peak_local_max
from skimage import data, img_as_float

im = img_as_float(data.coins())

# use ndimage to find the coordinates of maximum peaks
image_max = ndi.maximum_filter(im, size=20) == im

j, i = np.where(image_max)
coordinates_2 = np.array(zip(i,j))

# use skimage to find the coordinates of local maxima
coordinates = peak_local_max(im, min_distance=20)

# display results
fig, axes = plt.subplots(1, 2, figsize=(8, 3), sharex=True, sharey=True)
ax = axes.ravel()

ax[0].imshow(im, cmap=plt.cm.gray)
ax[0].plot(coordinates_2[:, 0], coordinates_2[:, 1], 'r.')
ax[0].axis('off')
ax[0].set_title('Maximum filter')

ax[1].imshow(im, cmap=plt.cm.gray)
ax[1].autoscale(False)
ax[1].plot(coordinates[:, 1], coordinates[:, 0], 'r.')
ax[1].axis('off')
ax[1].set_title('Peak local max')

fig.tight_layout()

plt.show()

这给出了每种方法的下一个峰:

我明白 maximum_filter 的参数 size 不等同于 peak_local_maxmin_distance,但我想知道是否有方法其中两者给出相同的结果。这可能吗?

关于 Whosebug 的一些相关问题是:

Get coordinates of local maxima in 2D array above certain value

Peak detection in a 2D array

你想出解决办法了吗?

我认为朝这个方向迈出的一步就是在最大过滤器中设置 size=41。 这给了我相当相似但不完全相同的结果。 这背后的想法是 peak_local_max2 * min_distance + 1 指定的区域中寻找峰值(来源:Documentation)。

ndi.maximum_filter识别出的附加峰大部分靠近边界,但在图片中间也有两个附加峰(附加峰用蓝色标记)。

Peaks

假设 peak_local_max 采用某种逻辑去除边界峰和靠近其他峰的峰。最有可能基于峰值。