problem with using Gabor filter to segment floor

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 commentaires

Please please help when implementing more than once the output is an edge instead of the cut-off part
I don't know what that means. If you need help, post a new question after reading the link below.
Please please help when implementing more than once the output is an edge instead of the cut-off part
OK, but @mustafa khalil please give the link to your code so we don't hijack @hajer jon 's code
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
@hajer jon has not been seen here in a year and a half so I doubt he will help you.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 5 Août 2019

2 votes

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 commentaires

hajer jon
hajer jon le 5 Août 2019
thank you for answer
actually, I need to segment floor in different videos with different density so I can't get empty space snapshot .
OK, so what about the mode?
hajer jon
hajer jon le 5 Août 2019
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.

Connectez-vous pour commenter.

Shashank Gupta
Shashank Gupta le 2 Août 2019

1 vote

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 commentaire

hajer jon
hajer jon le 4 Août 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 ??

Connectez-vous pour commenter.

Question posée :

le 28 Juil 2019

Commenté :

le 20 Fév 2021

Community Treasure Hunt

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

Start Hunting!

Translated by