def gabor_filter_kernel(
    ksize: int, sigma: int, theta: int, lambd: int, gamma: int, psi: int
) -> np.ndarray:

    # prepare kernel
    # the kernel size have to be odd
    if (ksize % 2) == 0:
        ksize = ksize + 1
    gabor = np.zeros((ksize, ksize), dtype=np.float32)

    # each value
    for y in range(ksize):
        for x in range(ksize):
            # distance from center
            px = x - ksize // 2
            py = y - ksize // 2

            # degree to radiant
            _theta = theta / 180 * np.pi
            cos_theta = np.cos(_theta)
            sin_theta = np.sin(_theta)

            # get kernel x
            _x = cos_theta * px + sin_theta * py

            # get kernel y
            _y = -sin_theta * px + cos_theta * py

            # fill kernel
            gabor[y, x] = np.exp(
                -(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)
            ) * np.cos(2 * np.pi * _x / lambd + psi)

    return gabor