Image 如何使用Gabor滤波器检测目标?

Image 如何使用Gabor滤波器检测目标?,image,matlab,image-processing,video-processing,gabor-filter,Image,Matlab,Image Processing,Video Processing,Gabor Filter,我想应用Gabor滤波器来检测图像中显示的车辆。 这是我的密码: clear all close all clc A=imread('image4.jpg'); %read image A = imresize(A,0.25); %resize image by 25% to inc. speed Agray=rgb2gray(A); %convert to gray to inc. ops figure imshow(A) imageSize = size(A); %calculate t

我想应用Gabor滤波器来检测图像中显示的车辆。 这是我的密码:

clear all
close all
clc

A=imread('image4.jpg'); %read image
A = imresize(A,0.25); %resize image by 25% to inc. speed
Agray=rgb2gray(A); %convert to gray to inc. ops
figure
imshow(A)

imageSize = size(A); %calculate the image size A
numRows = imageSize(1); %number of rows
numCols = imageSize(2); %number of columns

wavelengthMin = 4/sqrt(2); %wavlength in increasing powers of two starting from 4/sqrt(2) up to the hypotenuse length of the input image
wavelengthMax = hypot(numRows,numCols); %max wavelength = hypot of rows and columns
n = floor(log2(wavelengthMax/wavelengthMin)); %calculating floor points
wavelength = 2.^(0:(n-2)) * wavelengthMin; %wavelength calculation

deltaTheta = 45; %choose between 0 and 150 in steps of 30 degrees
orientation = 0:deltaTheta:(180-deltaTheta); %orientation of source image

g = gabor(wavelength,orientation); %calculating gabor function values g = 1*24


gabormag = imgaborfilt(Agray,g); %gabor magnitude from source image

for i = 1:length(g) % length of g = 24
    sigma = 0.5*g(i).Wavelength; %choose a sigma that is matched to the Gabor filter that extracted each feature
    K = 2; % smoothing term K random value
    gabormag(:,:,i) = imgaussfilt(gabormag(:,:,i),K*sigma); %imgaussfilt Gaussian Smoothing Filters to Images
end

X = 1:numCols; %1 to 317 columns
Y = 1:numRows; %1 to 176 rows
[X,Y] = meshgrid(X,Y); %Create 2-D grid coordinates with X-coordinates defined by the vector X and Y-coordinates defined by the vector Y
featureSet = cat(3,gabormag,X); 
featureSet = cat(3,featureSet,Y);

numPoints = numRows*numCols; %numPoints = 124848
X = reshape(featureSet,numRows*numCols,[]); %Reshaping data into a matrix X of the form expected by the kmeans function

X = bsxfun(@minus, X, mean(X)); %Normalize features to be zero mean
X = bsxfun(@rdivide,X,std(X)); %Normalize features to be unit variance

coeff = pca(X); %returns the principal component coefficients
feature2DImage = reshape(X*coeff(:,1),numRows,numCols); %returns the numRows-by-numCols matrix, which has the same elements as X*coeff(:,1). The elements are taken column-wise from X*coeff(:,1) to fill in the elements of the numRows-by-numCols matrix
figure
imshow(feature2DImage,[])

L = kmeans(X,4,'Replicates',12); %

L = reshape(L,[numRows numCols]);
figure
imshow(label2rgb(L)) %label matrix to rgb image

Aseg1 = zeros(size(A),'like',A);
Aseg2 = zeros(size(A),'like',A);
BW = L == 2;
BW = repmat(BW,[1 1 3]);
Aseg1(BW) = A(BW);
Aseg2(~BW) = A(~BW);
figure
imshowpair(Aseg1,Aseg2,'montage');
上述代码是从

这是我的图像(image4.jpg),我正在为其应用Gabor滤波器来检测车辆:

嗯。关于我的上述问题,这里有更多的观点: 1.每次我运行这段代码,都会得到不同的输出。 2.我可以在对象周围插入一个框吗?如果是,请建议我。 3.在Gabor滤波器的输出中,我得到了什么


感谢是预付款:)

您可能需要从以下内容开始。该函数将告诉您在图像中的每个点上存在多少给定的空间频率。因此,它们本身不能用于检测汽车,因为汽车不是特定的频率。@CrisLuengo,那么如何从地板上提取狗,在MATLAB示例中给出:使用Gabor滤波器的纹理分割它将狗与瓷砖区分开来,但无法识别具有随机背景的狗。瓦片形成了一种非常均匀的纹理,这就是被识别出来的。好吧,@CrisLuengo。你能详细解释我的第三点吗?解释Gabor滤波器是一个完整的讲座。由于这个原因,这种类型的问题不适合我。有很多资源可以解释它:书籍、网站、课堂讲稿。。。对不起,我不能抽出一个小时来帮助您理解它们。:)