lungseg.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:NoduleX_code 作者: jcausey-astate 项目源码 文件源码
def find_hist_peaks(img, drop_first_max=False):
    '''Finds the first two interior peaks in the histogram; usually a good binary
    threshold lies halfway between these two peaks.'''
    import scipy.signal as sig
    array        = sitk.GetArrayFromImage(img)

    hist         = np.histogram(array, 16)
    hist_counts  = np.array(hist[0])
    hist_centers = np.array(hist[1])
    peaks        = sig.argrelextrema(hist_counts, np.greater)[0]

    if hist_counts[peaks[0]] < (0.01 * (hist_counts[peaks].mean())):  # Don't allow a "noise" peak at the beginning.
        peaks = peaks[1:]

    if len(peaks) < 2: # Only one peak is found if the other peak is really at the edge.
        peaks = np.array([0, peaks[0]])
    elif hist_counts[0] > hist_counts[peaks[0]]:
        if not drop_first_max:
            peaks = np.array([0, peaks[0]])
    elif drop_first_max:
        peaks = np.array([peaks[1], peaks[2]])

    i_L    = hist_centers[peaks[0]]
    i_FM   = hist_centers[peaks[1]]
    return i_L, i_FM
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号