How is multiclass classification and finding accuracy using ANN from the exracted features by LBP done?

6 views (last 30 days)
I have 5 class of images and in each class I have 5 images and I have extracted features using LBP(Local Binary Pattern) and I need to classify and find accuracy of it using ANN from the extracted features(it contains histogram of 0-255 ),Guide me please if possible with a code?
  3 Comments
Sanjib
Sanjib on 28 Jan 2022
i=importdata('features.mat');
label=[1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]
In the features.mat files extracted features of 25 images are there and it has 5 differerent class and each class contains 5 element. now taking 4 images from each class I need to train using ANN and the remaining must use as test and find the accuracy.

Sign in to comment.

Answers (1)

Ayush Aniket
Ayush Aniket on 5 May 2025
A simple way to do this would be as follows:
  1. Load Features and Labels -
% Load features
data = importdata('features.mat'); % data should be 25x256 (if using LBP histograms)
% Labels (provided)
label = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]';
2. Split Data (4 Train, 1 Test per Class) -
trainIdx = [];
testIdx = [];
for c = 1:5
idx = find(label == c);
trainIdx = [trainIdx; idx(1:4)];
testIdx = [testIdx; idx(5)];
end
XTrain = data(trainIdx, :)';
YTrain = label(trainIdx)';
XTest = data(testIdx, :)';
YTest = label(testIdx)';
3. Prepare Targets for ANN Define and Train ANN -
% Convert labels to categorical for ANN
YTrain_cat = full(ind2vec(YTrain)); % Converts to one-hot encoding
YTest_cat = full(ind2vec(YTest));
% Simple feedforward network with one hidden layer of 10 neurons
net = patternnet(10);
% Train the network
net = train(net, XTrain, YTrain_cat);
However, your data has quite less number of images(25) compared to number of features(256). In such cases, its highly likely that the ANN will overfit the data. You can try the following approaches to mitigate the overfitting:
  1. Using PCA to reduce dimensionality: https://www.mathworks.com/help/stats/pca.html
  2. With so little data, classical machine learning methods (e.g., SVM, k-NN, LDA) often outperform neural networks.
  3. Finally, you can try data augmentation: https://www.mathworks.com/help/deeplearning/ug/image-augmentation-using-image-processing-toolbox.html

Community Treasure Hunt

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

Start Hunting!