Created
October 19, 2012 12:38
-
-
Save odebeir/3918044 to your computer and use it in GitHub Desktop.
Example of Gabor filter usage
This file contains hidden or 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
#opencv | |
import cv2.cv as cv | |
import cv2 | |
import numpy as np | |
def build_filters(): | |
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): | |
results = [] | |
for kern,params in filters: | |
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern) | |
results.append[fimg] | |
return results | |
# main | |
g = some_image | |
filters = build_filters() | |
filtered_images = process(g, filters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment