No account yet ?
In image processing, a Gabor filter is a linear filter used for texture analysis, meaning it analyzes content of specific frequencies.
It is a linear filter whose impulse response is a sinusoid modulated by a Gaussian function.
It is named after the Hungarian-born English physicist Dennis Gabor.
Temporal (or spatial) expression:
In the temporal or spatial domain if it is an image, a Gabor filter is the product of a complex sinusoid and a Gaussian envelope.
Gabor(x, y) = exp(-(x2+y2)) cos(2 π x)
Tested in Anaconda and Python 3.7
import cv2 import numpy as np from matplotlib import pyplot as plt #The line below is necessary to show Matplotlib's plots inside a Jupyter Notebook %matplotlib inline from matplotlib import pyplot as plt #Use this helper function if you are working in Jupyter Lab #If not, then directly use cv2.imshow(<window name>, <image>) def showimage(myimage, figsize=[10,10]): if (myimage.ndim>2): #This only applies to RGB or RGBA images (e.g. not to Black and White images) myimage = myimage[:,:,::-1] #OpenCV follows BGR order, while matplotlib likely follows RGB order fig, ax = plt.subplots(figsize=figsize) ax.imshow(myimage, cmap = 'gray', interpolation = 'bicubic') plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis plt.show() myimage = cv2.imread("pexels-isabella-mariana-1988681.jpg") showimage(myimage) min_interval = 120 max_interval = 250 # Create a new image of the edges image_edge = cv2.Canny(myimage,min_interval,max_interval) showimage(image_edge) def create_gaborfilter(): # This function is designed to produce a set of GaborFilters # an even distribution of theta values equally distributed amongst pi rad / 180 degree filters = [] num_filters = 16 ksize = 35 # The local area to evaluate sigma = 3.0 # Larger Values produce more edges lambd = 10.0 gamma = 0.5 psi = 0 # Offset value - lower generates cleaner results for theta in np.arange(0, np.pi, np.pi / num_filters): # Theta is the orientation for edge detection kern = cv2.getGaborKernel((ksize, ksize), sigma, theta, lambd, gamma, psi, ktype=cv2.CV_64F) kern /= 1.0 * kern.sum() # Brightness normalization filters.append(kern) return filters def apply_filter(img, filters): # This general function is designed to apply filters to our image # First create a numpy array the same size as our input image newimage = np.zeros_like(img) # Starting with a blank image, we loop through the images and apply our Gabor Filter # On each iteration, we take the highest value (super impose), until we have the max value across all filters # The final image is returned depth = -1 # remain depth same as original image for kern in filters: # Loop through the kernels in our GaborFilter image_filter = cv2.filter2D(img, depth, kern) #Apply filter to image # Using Numpy.maximum to compare our filter and cumulative image, taking the higher value (max) np.maximum(newimage, image_filter, newimage) return newimage # We create our gabor filters, and then apply them to our image gfilters = create_gaborfilter() image_g = apply_filter(myimage, gfilters) showimage(image_g) min_interval = 120 max_interval = 250 # Create a new image of the edges image_edge = cv2.Canny(image_g,min_interval,max_interval) showimage(image_edge)
Original image
Filtered image (Gabor)
Original image + canny
Filtered image + canny
Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !
Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License