Apply 2D Gabor wavelet in Images

4 views (last 30 days)
Khawaja Asim
Khawaja Asim on 10 Aug 2014
Answered: Naga on 27 Sep 2024
Hi I want to apply 2D Gabor filter on images at four orientations (0, 45, 90, 135 degrees). The output for every pixel should be like a vector [m0 m45 m90 m135], where m is the magnitude of orientation at that angle. Can anyone help me with the code?

Answers (1)

Naga
Naga on 27 Sep 2024
Hello Asim,
Below is a sample code to apply 2D Gabor filters to an image at four orientations (0, 45, 90, and 135 degrees) and store the magnitudes in a vector for each pixel.
I = imread('sample.jpg');
I = rgb2gray(I);
% Define Gabor filter parameters
wavelength = 4;
orientationAngles = [0, 45, 90, 135];
bandwidth = 1;
[m, n] = size(I);
magnitudeMatrix = zeros(m, n, numel(orientationAngles));
% Apply Gabor filter at each orientation
for i = 1:numel(orientationAngles)
gaborFilter = gabor(wavelength, orientationAngles(i), ...
'SpatialFrequencyBandwidth', bandwidth);
magnitudeMatrix(:,:,i) = imgaborfilt(I, gaborFilter);
end
for i = 1:numel(orientationAngles)
subplot(2, 2, i);
imshow(magnitudeMatrix(:,:,i), []);
title(['Orientation: ', num2str(orientationAngles(i)), '°']);
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!