Using KNN to Classify a Single Image Example(error)

1 vue (au cours des 30 derniers jours)
Stefano Sironi
Stefano Sironi le 18 Mar 2020
I am working on images (extracted with some procedures) where I have to assign a specific class.
It can be a dark chocolate one(as the .PNG example attached) as well as the "Raffaello chocolate" and the golden "Rocher".
The features I decided to assign to my knn classifier(8 neighbors) are an lbp vector(but it gives me a 1X59 vector for each image, instead of 62, as the error seems to be) and a scalar that is the rgb standard deviation (of the reshaped image).
As I try to execute this instruction
predict(classifier, [lbp, std_rgb]);
I get
Error using ExhaustiveSearcher/knnsearch (line 149) Y must be a matrix with 62 columns.
Personally, I'm trying to get the not-black-only part of the .PNG image, so that I might process the lbp feature with knn.
Is there a way, for instance, to rotate the not-black part of the image easily(I already have a method that, given the binary image, takes me the vertices coordinates)?
I think I must get rid of the black "background" part of the image.
Any easier help is appreciated.
Ps: I'm using the extractLBPFeature(8 neighbors) method.

Réponses (1)

Aditya Patil
Aditya Patil le 23 Mar 2020
I understand that you want to create KNN model with LBP and RGB standard deviation as features.
Without the code, it would not be possible to point out the exact issue. However, based on the information provided, this is what I think.
When the “Upright” flag is set, which is the default value, the extractLBPFeatures function returns (P x P – 1) + 3) features, where P in number of neighbours. As neighbours are 8 in your case, this value turns out to be 59.
After including 3 RGB standard deviations, it should come out to be 62.
The Y parameter of KNN should be the output labels. Hence, it should expect only 1 column. The X parameter should expect 62 columns.
Is it possible that when creating the model, you are passing the 62 column vector to Y, instead of X? Also, when using the predict method, you should pass the 62 column vector, and not the 59 column vector from LBP.

Community Treasure Hunt

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

Start Hunting!

Translated by