MATLAB Answers


problem with using Gabor filter to segment floor

Asked by hajer jon on 28 Jul 2019
Latest activity Commented on by Image Analyst
on 6 Aug 2019
i excute this code to get floor from image but not all floor.
Agray = rgb2gray(I);Untitled.png
imageSize = size(I);
numRows = imageSize(1);
numCols = imageSize(2);
wavelengthMin = 4/sqrt(2);
wavelengthMax = hypot(numRows,numCols);
n = floor(log2(wavelengthMax/wavelengthMin));
wavelength = 2.^(0:(n-2)) * wavelengthMin;
deltaTheta = 45;%%good result if reduce no
orientation = 0:deltaTheta:(180-deltaTheta);
g = gabor(wavelength,orientation);
gabormag = imgaborfilt(Agray,g);
for i = 1:length(g)
sigma = 0.5*g(i).Wavelength;%%good result if reduse no
K = 3;
gabormag(:,:,i) = imgaussfilt(gabormag(:,:,i),K*sigma);
X = 1:numCols;
Y = 1:numRows;
[X,Y] = meshgrid(X,Y);
featureSet = cat(3,gabormag,X);
featureSet = cat(3,featureSet,Y);
numPoints = numRows*numCols;
X = reshape(featureSet,numRows*numCols,[]);
X = bsxfun(@minus, X, mean(X));
X = bsxfun(@rdivide,X,std(X));
coeff = pca(X);
feature2DImage = reshape(X*coeff(:,1),numRows,numCols);
Lg = kmeans(X,2,'Replicates',5);
Lg = reshape(Lg,[numRows numCols]);
Aseg1 = zeros(size(I),'like',I);
Aseg2 = zeros(size(I),'like',I);
BWg = Lg == 2;
BWg = repmat(BWg,[1 1 3]);
Aseg1(BWg) = I(BWg);
Aseg2(~BWg) = I(~BWg);


Sign in to comment.

2 Answers

Answer by Image Analyst
on 5 Aug 2019

It looks like a frame from a video. Assuming the humans are moving, it's probably best to either get a snapshot when no one is on the floor, or if you can't get that, then take multiple frames spaced minutes apart and use the mode. The mode will assume that the floor color is the most common color at that position since people are not on it more than they are not on it.


Show 1 older comment
OK, so what about the mode?
How can i use mod ?
Save up a bunch of frames for training, then take a histogram of each pixel getting the mode value (or use the mode() function, if there is one). Then create an image where each pixel is the mode.

Sign in to comment.

Answer by Shashank Gupta on 2 Aug 2019

I understand that you want to segment out some texture from the image which is floor in your case. Gabor filters are traditional approach for unsupervised segmentation still they offer the best simultaneous localization of spatial and frequency information. However, it has some limitations, maximum bandwidth offer by Gabor filter is limited, so one seeking broad spectral information with maximum spatial localization is not optimal. I suggest you check the spectrum of image first and see does it satisfy the Bandwidth limitation and try changing the hyperparameter which are involved in Gabor filter. You can also try changing the number of Cluster in K-means which give more flexibility to handle the frequency distribution.

  1 Comment

thank you somuch for answer
I traied change kmean value and segma that make good results but it change when repeat run for code!!
about spectrum how can check the spectrum in matlab?use fft2() ?it gave me very big array 1080x1920x3 complex double how can help me in slution ??

Sign in to comment.