最大滤波器用于查找局部最大值。此操作将扩展原始图像,并合并相邻的局部最大值,使其小于扩展的大小。原始图像等于展开图像的位置将作为局部最大值返回。
如果indices = True(行、列…)坐标的峰值。
min_distance : int,可选
最小数量的像素分离地区的山峰2 * min_distance + 1(即山峰相隔至少min_distance)。 发现峰的最大数量,使用min_distance = 1
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
%matplotlib inline
im = img_as_float(data.coins())
# image_max is the dilation of im with a 20*20 structuring element
# It is used within peak_local_max function
image_max = ndi.maximum_filter(im, size=20, mode='constant')
# Comparison between image_max and im to find the coordinates of local maxima
coordinates = peak_local_max(im, min_distance=20) #返回[行,列],即[y, x]
#print(coordinates)
# display results
fig, axes = plt.subplots(1, 3, figsize=(18, 6), sharex=True, sharey=True)
ax = axes.ravel()
ax[0].imshow(im, cmap=plt.cm.gray)
ax[0].axis('off')
ax[0].set_title('Original')
ax[1].imshow(image_max, cmap=plt.cm.gray)
ax[1].axis('off')
ax[1].set_title('Maximum filter')
ax[2].imshow(im, cmap=plt.cm.gray)
ax[2].autoscale(False)
#ax[2].plot(coordinates[:, 1], coordinates[:, 0], 'r.')
ax[2].plot(73, 259, 'r.')
ax[2].axis('off')
ax[2].set_title('Peak local max')
fig.tight_layout()
plt.show()