Jos*_*lez 7 python scikit-image ndimage
我试图找到给定图像的一些相对最大值。据我所知,有两种可能的方法,第一种是使用scipy.ndimage.maximum_filter(),第二种是使用 skimage.feature.peak_local_max()。
为了比较这两种方法,我修改了此处显示的skimage 的示例,以便比较找到的峰值。
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()
Run Code Online (Sandbox Code Playgroud)
这给出了每种方法的下一个峰值:

我知道参数sizeformaximum_filter不等于min_distancefrom peak_local_max,但我想知道是否有一种方法可以给出相同的结果。那可能吗?
stackoverflow 上的一些相关问题是:
| 归档时间: |
|
| 查看次数: |
5996 次 |
| 最近记录: |