【问题标题】:Finding image peaks using ndimage.maximum_filter and skimage.peak_local_max使用 ndimage.maximum_filter 和 skimage.peak_local_max 查找图像峰值
【发布时间】:2019-10-02 12:59:42
【问题描述】:

我试图找到给定图像的一些相对最大值。我知道有两种可能的方法,第一种是使用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_max 中的min_distance,但我想知道是否有一种方法可以同时给出相同的结果。这可能吗?

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

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

Peak detection in a 2D array

【问题讨论】:

    标签: python scikit-image ndimage


    【解决方案1】:

    你能想出解决办法吗?

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

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

    Peaks

    假设peak_local_max 采用一些逻辑来去除边界峰和接近其他峰的峰。很可能基于峰值的值。

    【讨论】:

    • 你是对的!我弄乱了最大过滤器使用正方形区域而 peak_loca_max 只使用半径的事实。另一部分是我在您分享的文档中看到peak_local_max 有一个名为exclude_border 的参数。默认情况下它等于min_distance,这会删除边界点。如果您对此进行编辑,我将接受答案作为解决方案。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多