Gabor Filters

Gabor filters are used to extract features from an image. They extract spatial frequency content in a certain direction. Brainlit’s Gabor implementation can be used for nD images

[ ]:
import numpy as np
from brainlit.preprocessing import gabor_filter
from skimage import data
import matplotlib.pyplot as plt

img = data.brick()

frequencies = [0.1, 0.1, 0.25, 0.25]
phi = [0, np.pi / 2, 0, np.pi / 2]

plt.figure()
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.title("Original Image")
plt.show()

plt.figure()
for i in range(4):
    plt.subplot(2, 2, i + 1)
    filtered = gabor_filter(img, 5, phi[i], frequencies[i], truncate=3)
    plt.imshow(filtered[0], cmap="gray")
    plt.xticks([])
    plt.yticks([])
    if i == 0:
        plt.title("Orientation=0")
        plt.ylabel("Frequency=0.1")
    elif i == 1:
        plt.title("Orientation=\u03C0/2")
    elif i == 2:
        plt.ylabel("Frequency=0.25")
plt.show()
[ ]: