Skip to content

Instantly share code, notes, and snippets.

@kendricktan
Created May 16, 2016 01:07
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save kendricktan/93f0da88d0b25087d751ed2244cf770c to your computer and use it in GitHub Desktop.
Save kendricktan/93f0da88d0b25087d751ed2244cf770c to your computer and use it in GitHub Desktop.
Gabor kernel filter example in python
import numpy as np
import cv2
# cv2.getGaborKernel(ksize, sigma, theta, lambda, gamma, psi, ktype)
# ksize - size of gabor filter (n, n)
# sigma - standard deviation of the gaussian function
# theta - orientation of the normal to the parallel stripes
# lambda - wavelength of the sunusoidal factor
# gamma - spatial aspect ratio
# psi - phase offset
# ktype - type and range of values that each pixel in the gabor kernel can hold
g_kernel = cv2.getGaborKernel((21, 21), 8.0, np.pi/4, 10.0, 0.5, 0, ktype=cv2.CV_32F)
img = cv2.imread('test.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
filtered_img = cv2.filter2D(img, cv2.CV_8UC3, g_kernel)
cv2.imshow('image', img)
cv2.imshow('filtered image', filtered_img)
h, w = g_kernel.shape[:2]
g_kernel = cv2.resize(g_kernel, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
cv2.imshow('gabor kernel (resized)', g_kernel)
cv2.waitKey(0)
cv2.destroyAllWindows()
@intsynko
Copy link

intsynko commented Mar 2, 2021

You example is very simple, but very understandable. I'm improve this example to interactive dashboard, mayby it will be helped for someone: https://github.com/Kostya-228/gabor_dashboard/tree/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment