Pas encore de compte ?
Dans le traitement d'image, un filtre Gabor est un filtre linéaire utilisé pour l'analyse de texture, ce qui signifie qu'il analyse un contenu de fréquences spécifiques.
C'est un filtre linéaire dont la réponse impulsionnelle est une sinusoïde modulée par une fonction gaussienne.
Il porte le nom du physicien anglais d'origine hongroise Dennis Gabor.
Expression temporelle (ou spatiale) :
Dans le domaine temporel ou spatial s'il s'agit d'une image, un filtre de Gabor est le produit d'une sinusoïde complexe et d'une enveloppe gaussienne.
Gabor(x, y) = exp(-(x2+y2)) cos(2 π x)
Testé sous Anaconda et 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)
Image originale
Image filtrée (Gabor)
Image originale + canny
Image filtrée + canny
Bienvenu, je m’appelle Eric Soupet et je suis l'administrateur du site elodees.com. elodees.com est un état de l'art de l'Intelligence Artificielle et se veut collaboratif, vous pouvez dès à présent proposer du contenu tels que des articles, des événements, des tutoriels, ... alors n'hésitez pas !
Crédit des images de la plate-forme : Pixabay - Pixabay License | Pexels - Pexels License