Как обнаружить объект с помощью Gabor Filter? - PullRequest
0 голосов
/ 04 июля 2018

Я хочу применить Gabor Filter для обнаружения транспортного средства, показанного на изображении. Вот мой код:

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');

Приведенный выше код скопирован с MathWork: сегментация текстуры с использованием фильтров Габора

Вот мое изображение (image4.jpg), для которого я применяю Gabor Filter для обнаружения транспортного средства: Размер изображения изначально 1000x557.

OK. Вот еще несколько моментов, касающихся моего вышеуказанного вопроса: 1. Каждый раз, когда я запускаю этот код, я получаю разные результаты. 2. Могу ли я вставить коробку вокруг объекта? Если да, пожалуйста, предложите мне. 3. Что именно я получаю на выходе Gabor Filter?

Спасибо, заранее:)

...