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

[1]:
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()
/opt/buildhome/python3.7/lib/python3.7/site-packages/nilearn/datasets/__init__.py:96: FutureWarning: Fetchers from the nilearn.datasets module will be updated in version 0.9 to return python strings instead of bytes and Pandas dataframes instead of Numpy arrays.
  "Numpy arrays.", FutureWarning)
../../_images/notebooks_preprocessing_gaborfilter_1_1.png
../../_images/notebooks_preprocessing_gaborfilter_1_2.png
[ ]: