Getting Started with the "Go" Gabor

Source: Internet
Author: User

Computer Vision TutorialssearchPrimary MenuSkip to Content
    • Tutorials
Gabor filters:a Practical OverviewApril, krishnamurthyj 5 Comments

In this tutorial, we shall discuss Gabor filters, a classic technique, from a practical perspective.

Do not panic on seeing the equation that follows. It has been included here as a mere formality.

In the realms of image processing and computer vision, Gabor filters is generally used in texture analysis, Edge Detectio N, feature extraction, disparity estimation (in stereo vision), etc. Gabor filters is special classes of bandpass filters, i.e., they allow a certain ' band ' of frequencies and reject the oth ERs.

In the course of this tutorial, we shall first discuss the essential results so we obtain when Gabor filters is applied On images. Then we move on to discuss the different parameters that control the output of the filter. This tutorial was aimed at delivering a practical overview of Gabor filters; Hence, theoretical treatment is omitted (a tutorial that provides the essential theoretical rigor are currently in the pipe Line).

At each stage of the discussion, results of relevant filters has been displayed. The implementation, though contained in the tutorial itself, draws heavily from the Python script that comes along with Op Encv. It has been simplified further so it's simple for the beginners to work with.

To start with, Gabor filters is applied to images pretty much the same as is conventional filters. We have a mask (a more precise (cooler) of term for it would is ' convolution kernel ') that represents the filter. By a mask, we mean to say that we had an array (usually a 2D array since 2D images is involved) of pixels in which each Pixel is assigned a value (call it a ' weight '). This array was slid over every pixel of the image and a convolution operation are performed (you can refer to the following Link for more information on how a mask is applied to an image. Http://en.wikipedia.org/wiki/Kernel_ (image_processing)).

When a Gabor filter was applied to an image, it gives the highest response at edges and at points where texture changes. The following images show a test image and its transformation after the filter is applied.

Sample input to the Gabor Filteroutput of the Gabor filter

A Gabor Filter responds to edges and texture changes. When we say. A filter responds to a particular feature, we mean the filter have a distinguishing value at the spat Ial location of this feature (when we ' re dealing with applying convolution kernels in spatial domain, which is. The same holds for other domains, such as frequency domains, as well).

There is certain parameters that affect the output of a Gabor filter. In OpenCV Python, following are the structure of the function that's used to create a Gabor kernel.

Cv2.getgaborkernel (Ksize, Sigma, Theta, Lambda, Gamma, PSI, Ktype)

Each parameter are described very briefly in the OpenCV docs (http://docs.opencv.org/trunk/modules/imgproc/doc/filtering. HTML). Here's a brief introduction to each of the these parameters.

ksize is the size of the Gabor kernel. If ksize = (A, b), we then have a Gabor kernel of size a x b pixels. As with many-convolution kernels, ksize is preferably odd and the kernel are a square (just for the sake of uniformit Y).

Sigma is the deviation of the Gaussian function used in the Gabor filter.

Theta is the orientation of the normal to the parallel stripes of the Gabor function.

Lambda is the wavelength of the sinusoidal factor in the above equation.

Gamma is the spatial aspect ratio.

PSI is the phase offset.

ktype indicates the type and range of values that each pixel in the Gabor kernel can hold.

Now that we ' ve got a quaint feel of the all parameter means, let us delve deeper and understand the practical implicatio N of the variation of each of these parameters.

The Code

This is a simplified version of gabor_threads.py, which was available in the OpenCV Python library. (https://github.com/Itseez/opencv/blob/master/samples/python2/gabor_threads.py)

#!/usr/bin/env pythonimport numpy as Npimport cv2def build_filters (): Filters = [] Ksize = to theta in Np.arange (0, NP . Pi, np.pi/16): Kern = Cv2.getgaborkernel ((ksize, ksize), 4.0, theta, 10.0, 0.5, 0, Ktype=cv2. cv_32f) Kern/= 1.5*kern.sum () filters.append (Kern) return FILTERSDEF process (IMG, filters): Accum = Np.zeros_like (img) fo R Kern in filters:fimg = Cv2.filter2d (img, Cv2. CV_8UC3, Kern) Np.maximum (Accum, fimg, Accum) return accumif __name__ = ' __main__ ': Import sys print __doc__ TRY:IMG_FN = sys.argv[1] Except:img_fn = ' test.png ' img = cv2.imread (IMG_FN) if IMG is None:print ' Failed to load image file: ', img _FN sys.exit (1) filters = build_filters () res1 = Process (img, filters) cv2.imshow (' result ', res1) cv2.waitkey (0) Cv2.destr Oyallwindows ()

Ksize

On varying ksize, the size of the convolution kernel varies. In the code above we modify the parameter ksize, while keeping the kernel square and a odd size. We observe that there are no effect of the size of the convolution kernel on the output image. This also implies the convolution kernel are scale invariant, since scaling the kernel's size is analogous to scaling The size of the image. Here is a few results with varying ksize. For all the following images, sigma = 4.0, theta = 0, LAMBD = 10.0, gamma = 0.5, psi = 0, and Ktype = Cv2. cv_32f (i.e., each pixel of the convolution kernel holds a weight which was a 32-bit floating point number).

Input imageksize = 31ksize = x 51ksize = 151 x 151ksize = 531 x 531

(Roll over the images-to-view more information on each of the them).

Sigma

This parameter controls the width of the Gaussian envelope used in the Gabor kernel. Here is a few results obtained by varying this parameter.

Sigma = 2sigma = 3sigma = 4sigma = 5sigma = 6

Theta

This was perhaps one of the most important parameters of the Gabor filter. This parameter decides, what kind of features, the filter responds to. For example, giving Theta a value of zero means then the filter is responsive only to horizontal features only. So, in order to obtain features at various angles in an image, we divide the interval between 0 and the. s, and compute a Gabor kernel for each value of theta thus obtained. Note that we ' ve chosen just because it is the default value in the OpenCV implementation. These parameter values could is modified to suit specific purposes. Following is the results of varying theta on the above input image.

theta = 11.25theta = 22.5theta = 33.75theta = 45theta = 56.25theta = 67.5theta = 78.75theta = 90theta = 101.25theta = 112. 5theta = 123.75theta = 135theta = 146.25theta = 157.5theta = 168.75theta = 180

Lambda

Here's the variation with Lambda (theta are set to zero).

Lambda = 8lambda = 9lambda = 10lambda = 11lambda = 12

Gamma

Gamma controls the ellipticity of the Gaussian. When gamma = 1, the Gaussian envelope is circular.

Gamma = 0.3gamma = 0.4gamma = 0.5gamma = 0.6gamma = 0.7gamma = 1.0

Psi

This parameter controls the phase offset.

PSI = 0PSI = 10psi = 50PSI = 90

So, we've examined the observable effects of various parameters on the output of the Gabor filter. Hope this tutorial helped. 'll is back with more than such tuts soon.

About these ads

Original address: https://cvtuts.wordpress.com/2014/04/27/gabor-filters-a-practical-overview/

Getting Started with the "Go" Gabor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.