【转】Gabor 入门

Computer Vision Tutorials

Search

Primary Menu Skip to content

Search for:

Gabor Filters : A Practical Overview

April 27, 2014 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 are generally used in texture analysis, edge detection, feature extraction, disparity estimation (in stereo vision), etc. Gabor filters are special classes of bandpass filters, i.e., they allow a certain ‘band’ of frequencies and reject the others.

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

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

To start with, Gabor filters are applied to images pretty much the same way as are conventional filters. We have a mask (a more precise (cooler) term for it would be ‘convolution kernel’) that represents the filter. By a mask, we mean to say that we have an array (usually a 2D array since 2D images are involved) of pixels in which each pixel is assigned a value (call it a ‘weight’). This array is slid over every pixel of the image and a convolution operation is 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 is 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 filter

Output of the Gabor filter

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

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

cv2.getGaborKernel(ksize, sigma, theta, lambda, gamma, psi, ktype)

Each parameter is 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 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 other convolution kernels, ksize is preferably odd and the kernel is a square (just for the sake of uniformity).

sigma is the standard 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 what each parameter means, let us delve deeper and understand the practical implication of the variation of each of these parameters.

The Code

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

#!/usr/bin/env python

import numpy as np
import cv2

def build_filters():
 filters = []
 ksize = 31
 for 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 filters

def process(img, filters):
 accum = np.zeros_like(img)
 for kern in filters:
 fimg = cv2.filter2D(img, cv2.CV_8UC3, kern)
 np.maximum(accum, fimg, accum)
 return accum

if __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.destroyAllWindows()

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 of an odd size. We observe that there is no effect of the size of the convolution kernel on the output image. This also implies that the convolution kernel is scale invariant, since scaling the kernel’s size is analogous to scaling the size of the image. Here are 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 is a 32-bit floating point number).

Input Image

ksize = 31 x 31

ksize = 51 x 51

ksize = 151 x 151

ksize = 531 x 531

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

sigma

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

sigma = 2

sigma = 3

sigma = 4

sigma = 5

sigma = 6

theta

This is 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 that 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 180 into 16 equal parts, and compute a Gabor kernel for each value of theta thus obtained. Note that we’ve chosen 16 just because it was the default value in the OpenCV implementation. These parameter values could be modified to suit specific purposes. Following are the results of varying theta on the above input image.

theta = 11.25

theta = 22.5

theta = 33.75

theta = 45

theta = 56.25

theta = 67.5

theta = 78.75

theta = 90

theta = 101.25

theta = 112.5

theta = 123.75

theta = 135

theta = 146.25

theta = 157.5

theta = 168.75

theta = 180

lambda

Here’s the variation with lambda (theta is set to zero).

lambda = 8

lambda = 9

lambda = 10

lambda = 11

lambda = 12

gamma

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

gamma = 0.3

gamma = 0.4

gamma = 0.5

gamma = 0.6

gamma = 0.7

gamma = 1.0

psi

This parameter controls the phase offset.

psi = 0

psi = 10

psi = 50

psi = 90

So, we’ve examined the observable effects of various parameters on the output of the Gabor filter. Hope this tutorial helped. Will be back with more of such tuts soon.

About these ads

原文地址:https://cvtuts.wordpress.com/2014/04/27/gabor-filters-a-practical-overview/

时间: 2024-10-14 02:15:12

【转】Gabor 入门的相关文章

R语言快速上手入门

R语言快速上手入门 课程学习网址:http://www.xuetuwuyou.com/course/196 课程出自学途无忧网:http://www.xuetuwuyou.com 课程简介 本教程深入浅出地讲解如何使用R语言玩转数据.课程中涵盖R语言编程的方方面面,内容涉及R对象的类型.R的记号体系和环境系统.自定义函数.if else语句.for循环.S3类R的包系统以及调试工具等.本课程还通过示例演示如何进行向量化编程,从而对代码进行提速并尽可能地发挥R的潜能.本课程适合立志成为数据科学家的

笔记:Spring Cloud Zuul 快速入门

Spring Cloud Zuul 实现了路由规则与实例的维护问题,通过 Spring Cloud Eureka 进行整合,将自身注册为 Eureka 服务治理下的应用,同时从 Eureka 中获取了所有其他微服务的实例信息,这样的设计非常巧妙的将服务治理体系中维护的实例信息利用起来,使得维护服务实例的工作交给了服务治理框架自动完成,而对路由规则的维护,默认会将通过以服务名作为 ContextPath 的方式来创建路由映射,也可以做一些特别的配置,对于签名校验.登录校验等在微服务架构中的冗余问题

linux入门基础知识及简单命令介绍

linux入门基础知识介绍 1.计算机硬件组成介绍 计算机主要由cpu(运算器.控制器),内存,I/O,外部存储等构成. cpu主要是用来对二进制数据进行运算操作,它从内存中取出数据,然后进行相应的运算操作.不能从硬盘中直接取数据. 内存从外部存储中取出数据供cpu运存.内存的最小单位是字节(byte) 备注:由于32的cpu逻辑寻址能力最大为32内存单元.因此32位cpu可以访问的最大内存空间为:4GB,算法如下: 2^32=2^10*2^10*2^10*2^2 =1024*1024*1024

JAVA通信系列二:mina入门总结

一.学习资料 Mina入门实例(一) http://www.cnblogs.com/juepei/p/3939119.html Mina入门教程(二)----Spring4 集成Mina http://www.cnblogs.com/juepei/p/3940396.html Apache Mina 入门实例--创建一个MINA时间服务http://loftor.com/archives/apache-mina-quick-start-guide.html MINA2.0用户手册中文版--系列文

Storm入门(四)WordCount示例

Storm API文档网址如下: http://storm.apache.org/releases/current/javadocs/index.html 一.关联代码 使用maven,代码如下. pom.xml  和Storm入门(三)HelloWorld示例相同 RandomSentenceSpout.java /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor lice

浅谈Ubuntu PowerShell——小白入门教程

早在去年八月份PowerShell就开始开源跨平台了,但是一直没有去尝试,叫做PowerShell Core. 这里打算简单介绍一下如何安装和简单使用,为还不知道PowerShell Core on Ubuntu的同学们提供一点小小的入门帮助,谢谢大家支持~ PowerShell Core是由Microsoft开发的运行在.Net Core上的开源跨平台的任务自动化和配置管理系统. 1.   在Ubuntu 16.04上安装PowerShell Core a)         导入公共存储库GP

2.vue.js 入门环境搭建

原文链接:http://blog.csdn.net/luckylqh/article/details/52863026?locationNum=2&fps=1 vue这个新的工具,确实能够提高效率,在经历的一段时间的摧残之后,终于能够有一个系统的认识了,下面就今天的收获做一个总结,也是vue入门的精髓: 1.要使用vue来开发前端框架,首先要有环境,这个环境要借助于node,所以要先安装node,借助于node里面的npm来安装需要的依赖等等. 这里有一个小技巧:如果在cmd中直接使用npm来安

学习mysql的笔记:mysql十大基本入门语句

学习mysql数据库,从最简单的十条入门语句开始.刚开始学习mysql,老师让我们用cmd控制台输入语句,而不是选择用工具输入,这是为了我们能够先熟悉mysql语句. 首先要先进入mysql,语句为:mysql -hlocalhost -uroot -p  然后回车,输入密码. C:\Users\Administrator>mysql -hlocalhost -uroot -p Enter password: ****** 成功进入的话会出现 Welcome to the MySQL monit

Java - Java入门(2-1am)

第一讲.Java入门 1. 计算机语言是人和计算机进行交互的一种工具,人们通过使用计算机语言编写程序来向计算机施令,计算机则执行程序,并把结果输出给用户. 2. 机器语言:由0.1序列构成的指令码组成 如:10000000  加        10010000减          11110000 打印 3. 汇编语言:用助记符号描述的指令系统 如: Mov   A, #10; Mov   B, #20; Add   A,  B; 4. 高级语言: 面向过程的高级语言:程序设计的基本单元为函数