Python: skimage gabor_kernel size not as expected

379 Views Asked by At

I am using the gabor kernel method from the scikit-image library for checking the orientations of my intensity image. According to the official documentation, it takes the following parameters:

gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, offset=0)

In my code, I am using the following code, so the size of the kernel is implicitly defined to 3.

    from skimage.filters import gabor_kernel
    frequency = (np.pi) / (2 * np.sqrt(2))
    theta = 0
    gkernel = gabor_kernel(frequency, theta=theta)
    print('theta=%d,\nfrequency=%.2f' % (theta * 180 / np.pi, frequency))
    print(gkernel)

enter image description here

I don t understand why the generated kernel is a matrix 15x15, when the size is set to 3.

Thanks for your help, Sebastien

1

There are 1 best solutions below

0
user3433489 On

The bandwidth option is a little mysterious. According to the documentation, "For fixed bandwidth, sigma_x and sigma_y will decrease with increasing frequency. This value is ignored if sigma_x and sigma_y are set by the user." I recommend specifying sigma_x and sigma_y for direct control.

Another gotcha for me was the frequency. It has units of inverse pixels. So it's more straightforward to specify a wavelength in pixels, and then frequency=1/wavelength. For example, if your wavelength is 10, using frequency = 1/10 will mean that the signal completes 1 full cycle in 10 pixels. Because of the way it's defined here, you don't need to worry about pi factors.