Apply Gabor filter or filter bank to 2-D image
Read an image into the workspace and convert the image to grayscale.
I = imread('board.tif'); I = im2gray(I);
Apply a Gabor filter to the image.
wavelength = 4; orientation = 90; [mag,phase] = imgaborfilt(I,wavelength,orientation);
Display the original image with plots of the magnitude and phase response calculated by the Gabor filter.
tiledlayout(1,3) nexttile imshow(I) title('Original Image') nexttile imshow(mag,) title('Gabor Magnitude') nexttile imshow(phase,) title('Gabor Phase')
Read image into the workspace.
I = imread('cameraman.tif');
Create array of Gabor filters, called a filter bank. This filter bank contains two orientations and two wavelengths.
gaborArray = gabor([4 8],[0 90]);
Apply filters to input image.
gaborMag = imgaborfilt(I,gaborArray);
Display results. The figure shows the magnitude response for each filter.
figure subplot(2,2,1); for p = 1:4 subplot(2,2,p) imshow(gaborMag(:,:,p),); theta = gaborArray(p).Orientation; lambda = gaborArray(p).Wavelength; title(sprintf('Orientation=%d, Wavelength=%d',theta,lambda)); end
A— 2-D grayscale image
2-D grayscale image, specified as a numeric matrix.
wavelength— Wavelength of sinusoidal carrier
Wavelength of the sinusoidal carrier, specified as a number greater than
or equal to 2, in pixels/cycle. Typical values of
wavelength range from 2 up to the hypotenuse length
of the input image .
orientation— Orientation of filter
Orientation of the filter in degrees, specified as a numeric scalar in the range [0, 360]. The orientation is defined as the normal direction to the sinusoidal plane wave.
gaborbank— Gabor filter bank
gaborobject | array of
Gabor filter bank, specified as a
gabor object or an array of
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'SpatialFrequencyBandwidth',2specifies a spatial frequency bandwidth of two octaves
SpatialFrequencyBandwidth— Spatial-frequency bandwidth
1(default) | numeric scalar
Spatial-frequency bandwidth, specified as a numeric scalar in units of octaves. The spatial-frequency bandwidth determines the cutoff of the filter response as frequency content in the input image varies from the preferred frequency, 1/lambda. Typical values for spatial-frequency bandwidth are in the range [0.5, 2.5].
SpatialAspectRatio— Ratio of semimajor and semiminor axes of Gaussian envelope
0.5(default) | positive number
Ratio of the semimajor and semiminor axes of Gaussian envelope (semiminor/semimajor), specified as a positive number. This argument controls the ellipticity of the Gaussian envelope. Typical values for spatial aspect ratio are in the range [0.23, 0.92].
mag— Magnitude response
Magnitude response for the Gabor filter or filter bank, returned as a
numeric matrix for a single filter or a numeric array for a filter bank. The
p-th plane of
mag is the
magnitude response for the Gabor filter of the same index,
phase— Phase response
Phase response for the Gabor filter or filter bank, returned as a numeric
matrix for a single filter or a numeric array for a filter bank. The
p-th plane of
phase is the phase
response for the Gabor filter of the same index,
If the image contains
the behavior of
imgaborfilt is undefined because Gabor
filtering is performed in the frequency domain.
For all input data types other than
imgaborfilt performs the computation in
double. Input images of type
are filtered in type
single. Performance optimizations may
result from casting the input image to
single prior to
Usage notes and limitations:
imgaborfilt supports the generation of C
code (requires MATLAB®
Coder™). For more information, see Code Generation for Image Processing.
SpatialAspectRatio must be compile-time constants.
The filter bank syntax is not supported.