python计算二维数组的峰值

python计算二维数组的峰值

import numpy as np
from scipy.ndimage.filters import maximum_filter
from scipy.ndimage.morphology import generate_binary_structure, binary_erosion
import matplotlib.pyplot as pp


def detect_peaks(nums):

    neighborhood = generate_binary_structure(2,2)

    local_max = maximum_filter(nums, footprint=neighborhood)==nums

    background = (nums==0)
    eroded_background = binary_erosion(background, structure=neighborhood, border_value=1)

    detected_peaks = local_max ^ eroded_background
    return np.nonzero(detected_peaks)

输出数组中峰值的所有峰值的索引

你可能感兴趣的:(点云处理,python,numpy,开发语言)