Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:14:12+00:00 2026-05-28T17:14:12+00:00

How do i apply these Gabor filter wavelets on an image ? close all;

  • 0

How do i apply these Gabor filter wavelets on an image ?

enter image description here

close all;
clear all;
clc;

% Parameter Setting
R = 128;
C = 128;
Kmax = pi / 2;
f = sqrt( 2 );
Delt = 2 * pi;
Delt2 = Delt * Delt;

% Show the Gabor Wavelets
for v = 0 : 4
    for u = 1 : 8
        GW = GaborWavelet ( R, C, Kmax, f, u, v, Delt2 ); % Create the Gabor wavelets
          figure( 2 );
     subplot( 5, 8, v * 8 + u ),imshow ( real( GW ) ,[]); % Show the real part of Gabor wavelets

    end

    figure ( 3 );
     subplot( 1, 5, v + 1 ),imshow ( abs( GW ),[]); % Show the magnitude of Gabor wavelets

end



function GW = GaborWavelet (R, C, Kmax, f, u, v, Delt2)


k = ( Kmax / ( f ^ v ) ) * exp( 1i * u * pi / 8 );% Wave Vector

kn2 = ( abs( k ) ) ^ 2;

GW = zeros ( R , C );

for m = -R/2 + 1 : R/2

    for n = -C/2 + 1 : C/2

        GW(m+R/2,n+C/2) = ( kn2 / Delt2 ) * exp( -0.5 * kn2 * ( m ^ 2 + n ^ 2 ) / Delt2) * ( exp( 1i * ( real( k ) * m + imag ( k ) * n ) ) - exp ( -0.5 * Delt2 ) );

    end

end

Edit: this is the dimensions of my image

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:14:13+00:00Added an answer on May 28, 2026 at 5:14 pm

    A typical use of Gabor filters is to calculate filter responses at each of several orientations, e.g. for edge detection.

    You can convolve a filter with an image using the Convolution Theorem, by taking the inverse Fourier transform of the element-wise product of the Fourier transforms of the image and the filter. Here is the basic formula:

    %# Our image needs to be 2D (grayscale)
    if ndims(img) > 2;
        img = rgb2gray(img);
    end
    %# It is also best if the image has double precision
    img = im2double(img);
    
    [m,n] = size(img);
    [mf,nf] = size(GW);
    GW = padarray(GW,[n-nf m-mf]/2);
    GW = ifftshift(GW);
    imgf = ifft2( fft2(img) .* GW );
    

    Typically, the FFT convolution is superior for kernels of size > 20. For details, I recommend Numerical Recipes in C, which has a good, language agnostic description of the method and its caveats.

    Your kernels are already large, but with the FFT method they can be as large as the image, since they are padded to that size regardless. Due to the periodicity of the FFT, the method performs circular convolution. That means that the filter will wrap around the image borders, so we have to pad the image itself as well to eliminate this edge effect. Finally, since we want the total response to all the filters (at least in a typical implementation), we need to apply each to the image in turn, and sum the responses. Usually one uses just 3 to 6 orientations, but it is also common to do the filtering at several scales (different kernel sizes) as well, so in that context a larger number of filters is used.

    You can do the whole thing with code like this:

    img = im2double(rgb2gray(img)); %# 
    [m,n] = size(img); %# Store the original size.
    
    %# It is best if the filter size is odd, so it has a discrete center.
    R = 127; C = 127;
    
    %# The minimum amount of padding is just "one side" of the filter.
    %# We add 1 if the image size is odd.
    %# This assumes the filter size is odd.
    pR = (R-1)/2;
    pC = (C-1)/2;
    if rem(m,2) ~= 0; pR = pR + 1; end;
    if rem(n,2) ~= 0; pC = pC + 1; end;
    img = padarray(img,[pR pC],'pre'); %# Pad image to handle circular convolution.
    
    GW = {}; %# First, construct the filter bank.
    for v = 0 : 4
        for u = 1 : 8
            GW =  [GW {GaborWavelet(R, C, Kmax, f, u, v, Delt2)}];
        end
    end
    
    %# Pad all the filters to size of padded image.
    %# We made sure padsize will only be even, so we can divide by 2.
    padsize = size(img) - [R C];
    GW = cellfun( ...
            @(x) padarray(x,padsize/2), ...
            GW, ...
            'UniformOutput',false);
    
    imgFFT = fft2(img); %# Pre-calculate image FFT.
    
    for i=1:length(GW)
        filter = fft2( ifftshift( GW{i} ) ); %# See Numerical Recipes.
        imgfilt{i} = ifft2( imgFFT .* filter ); %# Apply Convolution Theorem.
    end
    
    %# Sum the responses to each filter. Do it in the above loop to save some space.
    imgS = zeros(m,n);
    for i=1:length(imgfilt)
        imgS = imgS + imgfilt{i}(pR+1:end,pC+1:end); %# Just use the valid part.
    end
    
    %# Look at the result.
    imagesc(abs(imgS));
    

    Keep in mind that this is essentially the bare minimum implementation. You can choose to pad with replicates of the border instead of zeros, apply a windowing function to the image or make the pad size larger in order to gain frequency resolution. Each of these is a standard augmentation to the technique I’ve outlined above and should be trivial to research via Google and Wikipedia. Also note that I haven’t added any basic MATLAB optimizations such as pre-allocation, etc.

    As a final note, you may want to skip the image padding (i.e. use first code example) if your filters are always much smaller than the image. This is because, adding zeros to an image creates an artificial edge feature where the padding begins. If the filter is small, the wraparound from circular convolution doesn’t cause problems, because only the zeros in the filter’s padding will be involved. But as soon as the filter is large enough, the wraparound effect will become severe. If you have to use large filters, you may have to use a more complicated padding scheme, or crop the edge of the image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my company, these rules apply: Only testers are allowed to create issues. Developers
After spending a couple months studying DDD methodology, I've now began to apply these
Using jQuery UI gives me these nice stylesheets. These apply to the widgets, ...
Is there any way to apply an attribute to a model file in ASP.NET
Is there the way to apply greedy behavior to and keys in Visual Studio?
Is there a way to apply import for a particular imported file and not
Is there a way to apply bitmapeffects within a silverlight web project.
Is there a way I can apply '+ to '( 1 2 3)? edit:
Is there a pattern that I could apply to refactor this code? The only
Is there any possible way to apply more than CSS to a control through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.