新型getargs格式,但参数不是元组-gabor过滤

时间:2019-03-04 04:31:08

标签: python gabor-filter

我已经做了足够的研究,但是我找不到。

请找到以下Code Gabor过滤器功能:

def gabor_kernel(W, angle, freq):
    cos = math.cos(angle)
    sin = math.sin(angle)

    yangle = lambda x, y: x * cos + y * sin
    xangle = lambda x, y: -x * sin + y * cos

    xsigma = ysigma = 4

    return utils.kernel_from_function(W, lambda x, y:
        math.exp(-(
            (xangle(x, y) ** 2) / (xsigma ** 2) +
            (yangle(x, y) ** 2) / (ysigma ** 2)) / 2) *
        math.cos(2 * math.pi * freq * xangle(x, y)))

def gabor(im, W, angles):
    (x, y) = im.size
    im_load = im.load()

    freqs = frequency.freq(im, W, angles)
    print "computing local ridge frequency done"

    gauss = utils.gauss_kernel(3)
    utils.apply_kernel(freqs, gauss)

    for i in range(1, x / W - 1):
        for j in range(1, y / W - 1):
            kernel = gabor_kernel(W, angles[i][j], freqs[i][j])
            for k in range(0, W):
                for l in range(0, W):
                    im_load[i * W + k, j * W + l] = utils.apply_kernel_at(
                        lambda x, y: im_load[x, y],
                        kernel,
                        i * W + k,
                        j * W + l)

    return im

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Gabor filter applied")
    parser.add_argument("image", nargs=1, help = "Path to image")
    parser.add_argument("block_size", nargs=1, help = "Block size")
    parser.add_argument("--save", action='store_true', help = "Save result image as src_image_enhanced.gif")
    args = parser.parse_args()

    im = Image.open(args.image[0])
    im = im.convert("L")  # covert to grayscale
    im.show()

    W = int(args.block_size[0])

    f = lambda x, y: 2 * x * y
    g = lambda x, y: x ** 2 - y ** 2

    angles = utils.calculate_angles(im, W, f, g)
    print "calculating orientation done"

    angles = utils.smooth_angles(angles)
    print "smoothing angles done"

    result = gabor(im, W, angles)
    result.show()

    if args.save:
        base_image_name = os.path.splitext(os.path.basename(args.image[0]))[0]
        im.save(base_image_name + "_enhanced.gif", "GIF")

我正在尝试实现gabor过滤器以增强图像。我从google上获取了一个正在处理的代码段,该代码段给了我一个我不熟悉的错误,请通过以下所附代码指导我,以便该错误可以纠正。

**Error:**
calculating orientation done
smoothing angles done
computing local ridge frequency done
<type 'tuple'>
Traceback (most recent call last):
  File "gabor.py", line 73, in <module>
    result = gabor(im, W, angles)
  File "gabor.py", line 47, in gabor
    j * W + l)
SystemError: new style getargs format but argument is not a tuple

0 个答案:

没有答案