How can I do a simple binary image classification?

11 views (last 30 days)
Hi,
I'm not really new to MATLAB, just new to this whole Machine Learning thing.
I have to do a simple binary image classification. I don't care if it's a toolbox or just code, I just need to do it. I tried a couple of classification codes I found online on Github or on other sites, but most of them worked randomly and some of them worked for pre-defined images.
Those that worked on pre-defined images were neat (e.g.: http://www.di.ens.fr/willow/events/cvml2011/materials/practical-classification/), but I had issues applying on a new set of images, just because there were some .txt files (vectors of the name of the images, which was easy to replicate) and some .mat files (with both name and histogram).
I had issues creating the name and histogram in the same order, the piece of code that I use is:
for K = 1 : 4
filename = sprintf('image_%04d.jpg', K);
I = imread(filename);
IGray = rgb2gray(I);
H = hist(Igray(:), 32);
end
save('ImageDatabase.mat', 'I', 'H');
But for one reason or another, only the name and path of the last image remains stored (e.g. in this case, only image_0004 is stored in the name slot).
Another code that I found and it seemed easy was: https://github.com/rich-hart/SVM-Classifier , but the output is really random (for me) so if someone could explain to me what is happening I'd be grateful. There are 19 training images and 20 for test. Yet, if I remove one of the test images, 2 entries disappear from the Support Vector Structure?
Anyway, if you have a toolbox, or a more easy to adapt code or some explanations to the above codes, I'd be grateful.
Cheers!

Answers (1)

Walter Roberson
Walter Roberson on 15 Jan 2018
  9 Comments
Dorian Diaconu
Dorian Diaconu on 16 Jan 2018
I cannot thank you enough for your help. So as an interpretation to the SVMStruct is:
SupportVectorIndices: The vectors that were used as support (from the training set, 18 images were selected). SupportVectors (same as above). KernelFunction (linear classification). GroupNames (all thetrainign data).
But what about alpha and bias? Actually, where can I see exactly what vector to what class it belongs to?
Walter Roberson
Walter Roberson on 16 Jan 2018
  • Alpha — Vector of weights for the support vectors. The sign of the weight is positive for support vectors belonging to the first group, and negative for the second group.
  • Bias — Intercept of the hyperplane that separates the two groups in the normalized data space (according to the 'AutoScale' argument).
For the support vectors, look at the Alpha values to determine which class it was.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!