How can i extract and save LBP features of multiple images, so that i can use them as a DB features ?
Afficher commentaires plus anciens
Hii, I have a folder of 200 images, I want to extract the LBP features of each image and save them in an Excel sheet so that I can use them as a DB features and retrieve, based on them, the accurate images in a CBIR project. I used this code for the extraction but the output gives me the feature vector of only one image.
image_folder = 'C:\Users\Desktop\images\resized';
ext_img = '*.png';
files = dir(fullfile(image_folder, ext_img));
assert(numel(files) > 0, 'No file was found. Check that the path is correct');
my_img = struct('img', cell(size(files)));
for i = 1:numel(files)
Img = imread(fullfile(image_folder, files(i).name));
gray = rgb2gray(Img);
LBP_image = extractLBPFeatures(gray,'Cellsize',[32 32], 'Normaas i lization','None');
numNeigbors = 8 %%Reshape the LBP features into a number of neighbors -by- number of cells array to access histograms for each individual cell.
numBins = numNeigbors*(numNeigbors-1)+3;
Cell_Hists = reshape(LBP_image,numBins,[]);
Cell_Hists = bsxfun(@rdivide,Cell_Hists,sum(Cell_Hists));%Normalize each LBP cell histogram using L1 norm
LBP_image = reshape(Cell_Hists,1,[]);%Reshape the LBP features vector back to 1-by- N feature vector
end
My second question is how to store them in Excel (in order to have the feature vectors of the 200 images). I used the xlswrite() function but as I said it gives me the vector of only one images (the last one) with a size of 1x3776.
4 commentaires
Image Analyst
le 25 Déc 2020
Modifié(e) : Image Analyst
le 25 Déc 2020
What variable did you pass to xlswrite()? What were you expecting? Did that part work as desired but you are only looking for how to batch process a sequence of images?
nissrine Neyy
le 25 Déc 2020
Lee Hau
le 27 Juin 2022
Hi, I have 100 images in my file to be extracted. I have used the coding shown but still not able to display all 100 LBP features. Below is the coding I use.
image_folder = 'C:\Users\HP\Desktop\ABC\A';
if ~isfolder(image_folder)
errorMessage = sprintf('Error: Folder not found:\n%s', image_folder);
fprintf('%s\n', errorMessage);
errordlg(errorMessage);
return;
end
ext_img = '*.png';
files = dir(fullfile(image_folder, ext_img));
assert(numel(files) > 0, 'No file was found. Check that the path is correct');
my_img = struct('img', cell(size(files)));
numberOfFiles = 100;%numel(files);
results = zeros(numberOfFiles);
for k = 1 : numberOfFiles
baseFileName = files(k).name;
fullFileName = fullfile(files(k).folder, baseFileName);
thisImage = imread(fullFileName);
grayImage = rgb2gray(thisImage);
LBP_image = extractLBPFeatures(grayImage,'CellSize',[32 32],'Normalization','None');
numNeigbors = 8;
Cell_Hists = reshape(LBP_image,numBins,[]);
Cell_Hists = bsxfun(@rdivide,Cell_Hists,sum(Cell_Hists));
results(k, :) = reshape(Cell_Hists,1,[]);
end
if numberOfFiles >= 0
writematrix(LBP_image,results);
end
Below error showed when I run the coding.
Unable to perform assignment because the size of the left side is 1-by-100 and the size of the right side is 1-by-59.
Error in array (line 25)
results(k, :) = reshape(Cell_Hists,1,[]);
Image Analyst
le 27 Juin 2022
@Lee Hau declare results with the right number of bins before the loop
numNeigbors = 8 %%Reshape the LBP features into a number of neighbors -by- number of cells array to access histograms for each individual cell.
numBins = numNeigbors*(numNeigbors-1)+3;
results = zeros(numberOfFiles, numBins);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur LBP - Local Binary Patterns dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
