Skip to content

Instantly share code, notes, and snippets.

@bikz05
Last active February 1, 2016 09:00
Show Gist options
  • Save bikz05/f524ebdcd69bbedce311 to your computer and use it in GitHub Desktop.
Save bikz05/f524ebdcd69bbedce311 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Import the modules
import cv2
import sys
import numpy as np
# Set the global parameters
'''
Sigma controls how fat the Gaussian is.
Theta controls the orientation i.e. which direction the filter responses to.
Lambd controls the freqency of the sinusoidal function.
Gamma controls the ellipticity of the Gaussian.
Psi controls the phase shift. (not used here)
'''
# Name of the window
win_name = 'Image'
def update():
global filter_size, sigma, theta, lambd, gamma, norm_filter
# Create the fiter banks
filter = cv2.getGaborKernel(filter_size, sigma, theta, lambd, gamma, ktype=cv2.CV_32F)
norm_filter = (filter + np.abs(np.min(filter)))/(np.abs(np.max(filter)) + np.abs(np.min(filter)))
# Create the callback functions
def set_k_size(x):
global filter_size
filter_size = (x, x)
update()
def set_sigma(x):
global sigma
sigma = x/10.
update()
def set_theta(x):
global theta
theta = x*np.pi/180.0
update()
def set_lambd(x):
global lambd
lambd = x/100.
update()
def set_gamma(x):
global gamma
gamma = x/100.0
update()
# The main function
if __name__ == '__main__':
global filter_size, sigma, theta, lambd, gamma, norm_filter
# Create the trackbars
# Set the dafault the values
filter_size = (50, 50)
sigma = 3
theta = 0
lambd = 10
gamma = .50
# Create the window
cv2.namedWindow(win_name, cv2.WINDOW_NORMAL)
# Create the trackbars
cv2.createTrackbar('Filter Size', win_name, 50, 100, set_k_size)
cv2.createTrackbar('Sigma*10', win_name, 3, 200, set_sigma)
cv2.createTrackbar('Theta (In degrees)', win_name, 0, 180, set_theta)
cv2.createTrackbar('Lambda/100', win_name, 10, 10000, set_lambd)
cv2.createTrackbar('Gamma*100', win_name, 50, 100, set_gamma)
# Update the filter bank
update()
# Create the fiter banks
filter = cv2.getGaborKernel(filter_size, sigma, theta, lambd, gamma, ktype=cv2.CV_32F)
print "Press ESC to quit the program"
while(cv2.waitKey(30)!=27):
cv2.imshow(win_name, norm_filter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment