-
-
Save avanish/3e90ab17f21e38b84cd9415813bb3634 to your computer and use it in GitHub Desktop.
Gabor kernel filter example in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment