How to apply classifier on extracted features?

1 view (last 30 days)
Regina N
Regina N on 20 Feb 2019
Answered: Purvaja on 20 Feb 2025
srcFiles = dir('C:\Users\LENOVO\Desktop\Genuine\2\*.png'); % the folder in which ur images exists
Features = cell(length(srcFiles),1) ;
Valid_points =cell(length(srcFiles),1) ;
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\LENOVO\Desktop\Genuine\2\',srcFiles(i).name);
I1 = rgb2gray(imread(filename));
points1 = detectSURFFeatures(I1); hold on;
strongest = points1.selectStrongest(10);
imshow(I1); hold on;
plot(strongest);
strongest.Location
[features1, interest_points] = extractFeatures(I1, points1);
Features{i} = features1 ;
Valid_points{i} = interest_points ;
figure; imshow(I1);
end
Features;
Valid_points;

Answers (1)

Purvaja
Purvaja on 20 Feb 2025
I understand that you want to classify the detected key points based on features.
I am approaching this by using K-means clustering, where we need to specify how many clusters we want. Using the clusters we can determine various classes and label them accordingly. Here clusters will be grouped according to their features (that describes their texture/pattern) similarity. Using these clusters we can then label each data point respectively, and apply suitable classifier on it. Here I have used SVM classifier to classify data points.
NOTE: You do not have to perform clustering if you already have labels ready for each feature that which cluster they belong to, so you can directly apply SVM model or else you may use unsupervised classifiers (like KNN) to train.
You can refer to following steps:
% Load Image
% Detect SURF Features
% Display detected keypoints
% Extract feature descriptors
% K-Means Clustering on Feature Descriptors
numClusters = 3; % Define number of clusters, I am defining here 3 clusters just for example, you may decide as you required
[idx, C] = kmeans(features, numClusters);
% Visualize Keypoints with Cluster Colors (Using Feature-Based Clustering)
figure;
imshow(inputImage);
hold on;
gscatter(validPoints.Location(:,1), validPoints.Location(:,2), idx, 'rgb', 'xod');
title ('Clustered Keypoints using Feature Descriptors');
legend ('Cluster 1', 'Cluster 2', 'Cluster 3');
% 'idx' contains the labels of our input features needed for classification
labels = idx;
% Train an SVM-based multiclass classifier
SVMModel = fitcecoc(features, labels);
% Predict class labels using the trained model
predictedLabels = predict(SVMModel, features); % Here features would be extracted from other image dataset to classify
% Visualize Classified Keypoints
figure; imshow(inputImage);
hold on;
gscatter(validPoints.Location(:,1), validPoints.Location(:,2), predictedLabels, 'rgb', 'o', 8);
title('Classified Keypoints using Multi-class SVM');
legend('Class 1', 'Class 2', 'Class 3');
For more clarification or adjusting it according to your input and output requirements, the following documentation links would be helpful:
You can also try this command in your MATLAB command window for specific release documentation on
  • “kmeans” clustering:
web(fullfile(docroot,'stats/kmeans.html'))
  • "Support vector machine" classification:
web(fullfile(docroot,'stats/support-vector-machine-classification.html'))
Hope this helps you!

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!