Classify binary images with multiple features
4 views (last 30 days)
Show older comments
I'm trying to classify a set of binary images in matlab. I have created a model using a lot of different images and have classified each one accordingly so that the model 'knows' which images belong to which class. Each image is represent as a feature vector, which is 1x59. I am successfully able to calculate the mean and covariance of class of images. The classifier uses maximum a posterior classification (MAP), but for some reason all the images in the test aren't being classified properly. The long equation I am using in the variable 'score' is the MAP calculation . Does anyone have any suggestions as to how to best classify an image?
function [classname] = classify(imagepath)
%Classify the image specified for the given image path
load('models');
%Assume all models use the same number of features
N = length(models(1).mean);
%(N+1)/2 because features considers positive and negative fourier
%therefore produces double the number of feature vectors
features = getFeatures(imagepath, ((N+1)/2));
maxscore = -inf;
%Find out which class has the highest score
for index = 1:length(models)
model = models(index);
%this should give a probablist score
score = max(log(model.prior) - 0.5*log(abs(model.cov)) - 0.5*(features - model.mean)'*inv(model.cov)*(features - model.mean));
%Score should be a 1x1 array not that monster
if score > maxscore
maxscore = score;
bestindex = index;
end
end
classname = classes(bestindex);
end
0 Comments
Answers (1)
Prajit T R
on 9 Apr 2018
Hi Edward
The Deep Learning toolbox can help in classifying images with a good accuracy. Check out this link: Image classification using Deep learning There's another documentation link wherein an example with the use of SVM for image classification is given. You may want to try that as well: SVM for Image classification
Hope this helps.
Cheers
0 Comments
See Also
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!