如何使用matlab自带的Gabor?

    xiaoxiao2025-07-28  20

    1、首先我们可以在命令行输入:help gabor 进行查看使用方法!

    2、制作一个gabor滤波器并应用于输入图像

    这里你可以选择自己创建一个checkerboard二维图像,也可以传入一个三维的图像再转成二维的图像也可以,我都尝试了,都可以的。

    %create a sample image clc;clear; tic; %自己制作一个二维的图像 % A = checkerboard(20); % figure; % imshow(A); % title('checkboard image'); %传入一张三维图像 img = imread('xiyang.jpg'); figure; imshow(img); title('三维的图像'); %转换为二维的图像 img2D = rgb2gray(img); figure; imshow(img2D); title('二维的图像'); %create an array of gabor filter wavelength = 20; orientation = [0 45 90 135]; g = gabor(wavelength,orientation); %apply the filter to check the image outMag = imgaborfilt(img2D,g);%这个是针对二维图像的,可以将三维图像转换为二维的图像 %display the results outSize = size(outMag); outMag = reshape(outMag,[outSize(1:2),1,outSize(3)]); figure,montage(outMag,'DisplayRange',[]); title('Montage of gabor magnitude output images'); toc; disp(['process time:',num2str(toc)]);

    上述的结果如下:

    3、可视化实时空间卷积核的带宽和方向

    clc; clear; tic; gabor_filter = gabor([5 10],[0 90]);%带宽和方向都是向量 figure; subplot(2,2,1); for p = 1:length(gabor_filter) subplot(2,2,p); imshow(real(gabor_filter(p).SpatialKernel),[]); lambda = gabor_filter(p).Wavelength; theta = gabor_filter(p).Orientation; title(sprintf('Re[h(x,y)], \\lambda = %d, \\theta = %d',lambda,theta)); end toc; disp(['process time:',num2str(toc)])

    上述结果如下:

    最新回复(0)