Gabor filters are often used for edge detection in computer vision tasks such as optical character recognition and facial expression recognition. In this blog post, I will demonstrate and provide source code for visualizing the “Gabor Space” using MATLAB. Given my research focus on faces, I will use facial images and video in my examples.


In the first step, a bank of Gabor filters with various scales and orientations can be generated from a mother wavelet. Below, I visualize a commonly-used bank of filters by representing the “real” component of each filter as a heatmap.

Gabor Filters Scale 1 Scale 2 Scale 3 Scale 4 Scale 5
Orientation 1
Orientation 2
Orientation 3
Orientation 4
Orientation 5
Orientation 6
Orientation 7
Orientation 8

In the second step, each filter can be convolved with the signal image at each pixel. This process is similar to what occurs in primate vision. Below, I visualize the “complex” component of each convolution as a heatmap. Hotter colors represent high response amplitude for a given filter at each spatial location in the signal image.

Gabor Space Scale 1 Scale 2 Scale 3 Scale 4 Scale 5
Orientation 1
Orientation 2
Orientation 3
Orientation 4
Orientation 5
Orientation 6
Orientation 7
Orientation 8

Finally, these convolutions can be used as features for machine learning or superimposed for full visualization.

Original Image Full Gabor Space

• Click here to download my source files for Gabor visualization in MATLAB.

MATLAB syntax for visualizing the Gabor filters:

load('GaborWavelets_cos_2.mat');
orient = size(GaborWavelets,1); %8
scales = size(GaborWavelets,2); %5
for o = 1:orient
    for s = 1:scales
        GW = GaborWavelets(o,s).GW;
        realGW = real(GW);
        f = figure(1);
        imagesc(realGW);
        set(gca,'YTick',[],'XTick',[]);
        axis square;
        filename = sprintf('gw_%d_%d.png',o,s);
        saveas(f,filename,'png');
    end
end

MATLAB syntax for visualizing the Gabor Space:

im = imread('original.jpg');
if length(size(im))>2, im = rgb2gray(im); end
im = double(im)/255;
avgIm = mean(im(:)); stdIm = std(im(:));
im = (im-avgIm)./stdIm;
waves = importdata('GaborWavelets_cos_2.mat');
master = cell(size(waves));
for o = 1:size(waves,1)
    for s = 1:size(waves,2)
        psiI = conv2(im,imag(waves(o,s).GW),'same');
        psiR = conv2(im,real(waves(o,s).GW),'same');
        master{o,s} = sqrt(psiI .^ 2 + psiR .^ 2);
        f = figure(1);
        imagesc(master{o,s});
        set(gca,'YTick',[],'XTick',[]);
        axis image;
        filename = sprintf('im_%d_%d.png',o,s);
        saveas(f,filename,'png');
    end
end
allgmp = sum(cat(3,master{:}),3);
imagesc(allgmp);
set(gca,'YTick',[],'XTick',[]);
axis image;
filename = 'im_sumall.png';
saveas(f,filename,'png');