problem with using Gabor filter to segment floor

2 views (last 30 days)
hi
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);
end
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);
  6 Comments
mustafa khalil
mustafa khalil on 20 Feb 2021
A = imread('kobi.png'); A = imresize(A,0.25); Agray = rgb2gray(A); figure imshow(A); imageSize = size(A); 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; orientation = 0:deltaTheta:(180-deltaTheta);
g = gabor(wavelength,orientation); gabormag = imgaborfilt(Agray,g); for i = 1:length(g) sigma = 0.5*g(i).Wavelength; K = 3; gabormag(:,:,i) = imgaussfilt(gabormag(:,:,i),K*sigma); end 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); figure imshow(feature2DImage,[]); L = kmeans(X,2,'Replicates',5); L = reshape(L,[numRows numCols]); figure imshow(label2rgb(L)); 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');
Please please help when implementing more than once the output is an edge instead of the cut-off part
Image Analyst
Image Analyst on 20 Feb 2021
@hajer jon has not been seen here in a year and a half so I doubt he will help you.

Sign in to comment.

Answers (2)

Image Analyst
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.
  4 Comments
Image Analyst
Image Analyst on 6 Aug 2019
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.


Shashank Gupta
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
hajer jon
hajer jon on 4 Aug 2019
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!