AlternativePeriodicityScoring.py 文件源码

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

项目:SlidingWindowVideoTDA 作者: ctralie 项目源码 文件源码
def getCutlerDavisFrequencyScore(I, doPlot = False):
    """
    Compute the frequency score suggested by Cutler and Davis, with a slight
    modification using Kurtosis instead of mean versus standard deviation
    :param I: An Nxd matrix representing a video with N frames at a resolution of
        d pixels
    :doPlot: If true, show the SSM and average power spectrum across all columns
    """
    N = I.shape[0]
    (D, _) = getSSM(I, N)
    F = np.zeros(N)
    #For linearly detrending
    A = np.ones((N, 2))
    A[:, 1] = np.arange(N)
    #Compute the power spectrum column by column
    for i in range(N):
        x = D[:, i]
        #Linearly detrend
        mb = np.linalg.lstsq(A, x)[0]
        y = x - A.dot(mb)
        #Apply Hann Window
        y = y*np.hanning(N)
        #Add on power spectrum
        F += np.abs(np.fft.fft(y))**2
    #Compute kurtosis of normalized averaged power spectrum
    F = F/np.sum(F)
    F[0:2] = 0 #Ignore DC component
    F[-1] = 0
    kurt = scipy.stats.kurtosis(F, fisher = False)
    M = np.mean(F)
    S = np.std(F)
    if doPlot:
        plt.subplot(121)
        plt.imshow(D, cmap='afmhot', interpolation = 'none')
        plt.subplot(122)
        plt.plot(F)
        plt.hold(True)
        plt.plot([0, N], [M, M], 'b')
        plt.plot([0, N], [M+2*S, M+2*S])
        plt.title("Kurtosis = %.3g"%kurt)
    return (np.max(F) - M)/S
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号