Reputation: 152
I'm using Local Binary Pattern (LBP
) to extract the features of group of images (500 images in Training folder and 100 Images in Test folder). Indeed, I had extracted these features successfully but I'm not sure whether they saved in correct way or not.
Here is a part of code that extract the features:
for x = 1:total_images
% Specify images names with full path and extension
full_name= fullfile(test_set, filenames(x).name);
% Read images from Training folder
I2 = imread(full_name);
I3=I2;
m=size(I2,1);
n=size(I2,2);
for i=2:m-1
for j=2:n-1
c=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>c;
I3(i-1,j)=I2(i-1,j)>c;
I3(i-1,j+1)=I2(i-1,j+1)>c;
I3(i,j+1)=I2(i,j+1)>c;
I3(i+1,j+1)=I2(i+1,j+1)>c;
I3(i+1,j)=I2(i+1,j)>c;
I3(i+1,j-1)=I2(i+1,j-1)>c;
I3(i,j-1)=I2(i,j-1)>c;
LBP (i,j) =I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+ ...
I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+ ...
I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
end
end
featureMatrix {x} = hist(LBP,0:255);
end
By using this code, I get LBP
features of all images but I'm not sure about saving them correctly in a matrix. How to save feature value from this histogram of LBP
image? I want to store this value for each image.
featureMatrix
is a matrix that data will stored in. It should be consist of 500 rows, each row should has all features of each image.
Any answer will be appreciated.
Upvotes: 0
Views: 1994
Reputation: 149
you should initialize the feature matrix before entering the outer loop (if you could know the size of LBP):
featureMatrix = zeros(total_images,size_LBP); % where size_LBP is the number of columns of LBP.
then replace featureMatrix {x} = hist(LBP,0:255);
in the loop with:
featureMatrix(x,:) = hist(LBP,255);
I hope this works for you!
Upvotes: 1