Skip to content

Instantly share code, notes, and snippets.

@odebeir
Last active November 8, 2021 12:49
Show Gist options
  • Select an option

  • Save odebeir/5237529 to your computer and use it in GitHub Desktop.

Select an option

Save odebeir/5237529 to your computer and use it in GitHub Desktop.
Small python code for building Gabor filters
# opencv
import cv2.cv as cv
import cv2
def build_filters():
""" returns a list of kernels in several orientations
"""
filters = []
ksize = 31
for theta in np.arange(0, np.pi, np.pi / 32):
params = {'ksize':(ksize, ksize), 'sigma':1.0, 'theta':theta, 'lambd':15.0,
'gamma':0.02, 'psi':0, 'ktype':cv2.CV_32F}
kern = cv2.getGaborKernel(**params)
kern /= 1.5*kern.sum()
filters.append((kern,params))
return filters
def process(img, filters):
""" returns the img filtered by the filter list
"""
accum = np.zeros_like(img)
for kern,params in filters:
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern)
np.maximum(accum, fimg, accum)
return accum
#main
filters = build_filters()
p = process(e, filters)
@shivakrishnagujju
Copy link
Copy Markdown

``import cv2.cv as cv
import cv2

def build_filters():
""" returns a list of kernels in several orientations
"""
filters = []
ksize = 31
for theta in np.arange(0, np.pi, np.pi / 32):
params = {'ksize':(ksize, ksize), 'sigma':1.0, 'theta':theta, 'lambd':15.0,
'gamma':0.02, 'psi':0, 'ktype':cv2.CV_32F}
kern = cv2.getGaborKernel(**params)
kern /= 1.5*kern.sum()
filters.append((kern,params))
return filters

def process(img, filters):
""" returns the img filtered by the filter list
"""
accum = np.zeros_like(img)
for kern,params in filters:
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern)
np.maximum(accum, fimg, accum)
return accum

#main
filters = build_filters()
p = process(e, filters)

@shivakrishnagujju
Copy link
Copy Markdown

sir/mam, i am new for this Python or Matlab code .so please tell me how to write this code in python or Matlab with step by step

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