Error using extractLBPFeatures>parseInputs Expected a string scalar or character vector for the parameter name.
2 views (last 30 days)
Show older comments
I have faced this error whle I was using extractLBPFeatures:
Error using extractLBPFeatures>parseInputs
Expected a string scalar or character vector for the parameter name.
Error in extractLBPFeatures (line 10)
params = parseInputs(I,varargin{:});
Error in face_recognition_model (line 52)
testFeatures{i} = extractLBPFeatures(img, numNeighbors, radius, numBins);
Code:
%Face Recognition using LRR
%% Load a dataset of grayscale face images
Dataset = imageDatastore('ExtendedYaleB', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
%% Split the data into training and testing sets
[trainImgs, testImgs] = splitEachLabel(Dataset, 0.7, 'randomized');
%% Extract local patches from the training images using the extractLBPFeatures function
numNeighbors = 8;
radius = 1;
numBins = numNeighbors*(numNeighbors-1)+3;
trainFeatures = cell(numel(trainImgs.Files),1);
for i = 1:numel(trainImgs.Files)
img = readimage(trainImgs,i);
trainFeatures{i} = LBPFeatures(img, numNeighbors, radius, numBins);
end
%% Train the local ridge regression model using the fitrlinear function and local ridge regression
lambda = 1;
span = 0.5;
for i = 1:numel(trainImgs.Files)
features = trainFeatures{i};
label = double(trainImgs.Labels(i));
idx = setdiff(1:numel(trainFeatures),i);
neighbors = vertcat(trainFeatures{idx});
neighborLabels = double(trainImgs.Labels(idx));
mdl = fitrlinear(neighbors,neighborLabels,'Learner','leastsquares','Lambda',lambda);
yhat = zeros(size(features));
for j = 1:size(features,1)
patch = features(j,:);
pred = predict(mdl,patch);
dist = pdist2(patch,neighbors);
w = exp(-dist.^2/(2*span^2));
yhat(j) = sum(w.*pred)/sum(w);
end
trainFeatures{i} = yhat;
end
trainFeatures = cell2mat(trainFeatures);
%% Train the linear regression model on the modified LBP features
mdl = fitrlinear(trainFeatures,double(trainImgs.Labels),'Learner','leastsquares','Lambda',lambda);
%% Save the model to a file
save('face_recognition_model.mat', 'mdl');
%% Extract local patches from the testing images and make predictions using the predict function
testFeatures = cell(numel(testImgs.Files),1);
for i = 1:numel(testImgs.Files)
img = readimage(testImgs,i);
testFeatures{i} = extractLBPFeatures(img, numNeighbors, radius, numBins);
end
testFeatures = cell2mat(testFeatures);
predictions = predict(mdl,testFeatures);
%% Evaluate the performance of the model using the confusionmat and classificationReport functions
confMat = confusionmat(testImgs.Labels,predictions);
classificationReport = classificationReport(testImgs.Labels,predictions);
%% Load the saved model from a file
load('face_recognition_model.mat');
%% Use the loaded model for prediction
testImg = imread('test_image.jpg');
testFeatures = extractLBPFeatures(testImg, numNeighbors, radius, numBins);
prediction = predict(mdl,testFeatures);
0 Comments
Answers (1)
Abhinav Aravindan
on 4 Dec 2024
Edited: Abhinav Aravindan
on 4 Dec 2024
The “extractLBPFeatures” function accepts the image as the first input argument, and the remaining arguments as Name-Value pairs. For instance:
lbpFeatures = extractLBPFeatures(I,'CellSize',[32 32],'Normalization','None');
The error you are encountering is likely due to the input arguments not being specified as Name-Value pairs. I would suggest replacing your code with the following to resolve the issue:
testFeatures{i} = extractLBPFeatures(img, "NumNeighbors", numNeighbors,"Radius", radius);
As per the documentation, “numBins” is not a valid input argument to the function but is used to reshape the LBP features to access histograms for each individual cell.
Please find attached below the relevant documentation for your reference:
0 Comments
See Also
Categories
Find more on Acoustics, Noise and Vibration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!