锐度的频谱和空间度量-如何计算幅度谱的斜率?

时间:2019-02-22 11:21:07

标签: python image-processing signal-processing fft dft

我正在尝试实施this paper中的S1测量(锐度的光谱测量-III-A节)。在这里,我们必须计算图像幅值谱的斜率(alpha),以测量清晰度。我能够编写算法的其他部分,但无法计算斜率。这是我的代码。函数“ alpha”是我计算幅值谱的地方,我认为使用它可以计算斜率,但不确定如何做到这一点-

def aplha(image_block):
    img_float32 = np.float32(image_block)

    dft = cv2.dft(img_float32, flags = cv2.DFT_COMPLEX_OUTPUT)
    dft_shift = np.fft.fftshift(dft)
    magnitude_spectrum = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))

    return output (??)

其余代码:

def S1_calc(alpha):
    tou1 = -3
    tou2 = 2
    output = 1 - (1 / (1 + np.exp(tou1 * (alpha - tou2))))
    return output

def lx(image_block):
    b = 0.7656
    k = 0.0364
    y = 2.2
    return np.power((b + k * image_block), y)

def contrast(lx_val):
    T1 = 5
    T2 = 2
    max_val = np.max(lx_val)
    min_val = np.min(lx_val)
    mean_val = np.mean(lx_val)
    return (((max_val - min_val) < T1) or (mean_val < T2))

def image_gray(image_RGB):
    output = (0.2989 * image_RGB[:,:,0] +
              0.5870 * image_RGB[:,:,1] +
              0.1140 * image_RGB[:,:,2])

    return output

def S1(gray_image, m = 32, d = 24):
    ### SPECTRAL MEASURE OF SHARPNESS ###

    # m = each block size
    # d = overlapping pixels of neighbouring blocks
    h,w = gray_image.shape
    output = gray_image.copy()

    row = 0
    while (row < h):
        col = 0
        while (col < w):

            top = row
            bottom = min(row + m, h)
            left = col
            right = min(col + m, w)

            image_block = gray_image[top : bottom, left : right]

            lx_val = lx(image_block)
            contrast_bool = contrast(lx_val)
            if contrast_bool==True:
                output[top : bottom, left : right] = 0
            else:
                alpha_val = aplha(image_block)
                output[top : bottom, left : right] = S1_calc(alpha_val)

            col = col + m - d
        row = row + m - d

    return output

我正在使用Jupyter Notebook Python 3.6

0 个答案:

没有答案