Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Open CV
  • scikit-image
  • pycairo
  • Pyglet
  • Python
  • Numpy
  • Pandas
  • Python Database
  • Data Analysis
  • ML Math
  • Machine Learning
  • NLP
  • Deep Learning
  • Deep Learning Interview Questions
  • ML Projects
  • ML Interview Questions
  • 100 Days of Machine Learning
Open In App
Next Article:
OpencV getGaborKernel() Method
Next article icon

OpencV getGaborKernel() Method

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn about cv2.getGaborKernel() for various rotations in Python.

Gabor filters are one of the most essential tools in Computer Vision. Gabor filters help in texture analysis, edge detection, and feature extraction. A Gabor kernel is a type of bandpass filter that is used to analyze images in relation to the frequency of content. The Gabor kernel consists of a Gaussian envelope multiplied by a sinusoidal wave. The Gaussian envelope controls the size and shape of the kernel. Sinusoidal wave controls their orientation and frequency.

Cv2.getGaborKernel()

The cv2.getGaborKernel() function in the OpenCV library provides a straightforward way to generate Gabor kernels with a variety of parameters. This function takes various parameters such as kernel size, sigma, frequency, orientation, and phase. 

Syntax of Cv2.getGaborKernel() function:

cv2.getGaborKernel(ksize, sigma, theta, lambd, gamma, psi=0, ktype=cv2.CV_32F)

Parameters:

  • ksize: It is the size of the filter kernel (width, height) in pixels. This can be a tuple or a single integer value.
  • sigma: Standard deviation of the Gaussian envelope.
  • theta: Orientation of the filter in degrees.
  • lambd: Wavelength of the sinusoidal factor.
  • gamma: Spatial aspect ratio (ellipticity) of the filter.
  • psi: Phase offset of the filter in degrees. This is an optional parameter and its default value is 0.
  • ktype:  Data type of the filter coefficients. This is an optional parameter and its default value is cv2.CV_32F, which represents a 32-bit floating-point data type.

Generating various rotation using cv2.getGaborKernel() in Python,

Use the orientation parameter to generate Gabor kernels with different rotations. The orientation parameter in the cv2.getGaborKernel() function rotates the Gabor kernel. By changing the orientation parameter, we get various orientations. Its values are in radians, from 0 to π. A loop with varying orientation values can create Gabor kernels with different orientations. We can then use the cv2.getGaborKernel() function to generate Gabor kernels for each orientation value.

Example: 

Firstly we import the required libraries cv2, NumPy, and matplotlib.pyplot. Defines all the values of parameters in Cv2.getGaborKernel() function. The loop defined in the code is looping through each orientation value in theta_range and generates a corresponding Gabor kernel using the cv2.getGaborKernel() function. The generated kernel is displayed using matplotlib.pyplot.imshow().
Colormap is set to grayscale with cmap='gray', and the title of the displayed image includes orientation value using plt.title(). The image is shown in a separate window by calling plt.show(). This will output different Gabor kernels with various orientations.

Python3
# Import required libraies import cv2 import numpy as np import matplotlib.pyplot as plt  # kernel size ksize = 31   # sigma for Gaussian envelope sigma = 5   # range of orientation values theta_range = np.arange(0, np.pi, np.pi / 4)  # frequency of sinusoidal wave frequency = 0.3   # phase of sinusoidal wave phase = 0    # for loop for generating different rotation for theta in theta_range:     kernel = cv2.getGaborKernel((ksize, ksize),                                 sigma, theta,                                 frequency, phase)     plt.imshow(kernel,                cmap='gray')     plt.title("Kernel with orientation = " + str(theta))     plt.show() 

Output:

Using cv2.getGaborKernel() for various rotations
 
Using cv2.getGaborKernel() for various rotations
 
Using cv2.getGaborKernel() for various rotations
 
Using cv2.getGaborKernel() for various rotations
 

In the above code, we can see how the orientation parameter of the cv2.getGaborKernel() function affects the rotation angle of the Gabor kernel. We can use this approach to generate Gabor kernels with different orientations for our various image-processing applications.

Conclusion

The cv2.getGaborKernel() function is a powerful tool in computer vision for generating Gabor kernels. By varying the orientation parameter, we can generate Gabor kernels with different rotations, which can be used in various image processing applications.

Technical Vocabulary

  • Bandpass filters block the things which we do not want to see or hear. It helps us see only specific things in a picture or a sound.
  • Gaussian envelope gives a soft to our image blur that helps to make things look smoother and less pixelated. It is used for smoothing out edges in pictures or making text easier to read.
  • Sinusoidal wave is a wavy line that goes up and down in a regular pattern. It is used in many signal-processing applications, like encoding and decoding information, or creating patterns in images.
  • A kernel is like a small matrix that helps to modify an image or a signal. In the Gabor kernel, a kernel is a special matrix that combines a Gaussian envelope with a sinusoidal wave. It is used in image processing applications to detect edges and highlight texture features in an image.

Next Article
OpencV getGaborKernel() Method

A

abhijeetsinghbhainser
Improve
Article Tags :
  • Python
  • OpenCV
  • Python-OpenCV
Practice Tags :
  • python

Similar Reads

    Python OpenCV | cv2.copyMakeBorder() method
    OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.copyMakeBorder() method is used to create a border around the image like a photo frame.   Syntax: cv2.copyMakeBorder(src, top, bottom, left, right, borderType, value) Parameters: src: It is the source image
    2 min read
    Python OpenCV | cv2.blur() method
    OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.blur() method is used to blur an image using the normalized box filter. The function smooths an image using the kernel which is represented as: Syntax: cv2.blur(src, ksize[, dst[, anchor[, borderType]]]) Pa
    2 min read
    Python OpenCV | cv2.cvtColor() method
    OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV. We will use some of color space conversion codes be
    4 min read
    cv2.imread() method - Python OpenCV
    OpenCV-Python is a Python library used to solve computer vision tasks. cv2.imread() method loads an image from the specified file. If the image cannot be read because of missing file, improper permissions or an unsupported/invalid format then it returns an empty matrix.Example:Pythonimport cv2 image
    2 min read
    Python OpenCV - getgaussiankernel() Function
    Python OpenCV getGaussianKernel() function is used to find the Gaussian filter coefficients. The Gaussian kernel is also used in Gaussian Blurring. Gaussian Blurring is the smoothing technique that uses a low pass filter whose weights are derived from a Gaussian function. In fact, this is the most w
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences