i want to train a knn classifier to segment an image into four classes. i train the classifier with four classes.but when testing the network I get only two classes. what could cause this error?
I don't have much experience with KNN classifiers, but love trying to tackle any kind of image processing problem, especially with our newly released software. I am very curious what kind of image you are trying to segment and would be very excited to see an example. I may be able to put together a recipe to segment it into four classes, without the need for classifier training. Would you be willing to give this a try? Thanks very much.
I also tried knn classification with MATLAB, and I got results as expected. There wouldn't be any problem if you used "knnclassify" function in MATLAB. I assume that the problem would be in your test data. How did you set up your dataset, how much proportion between number of samples test and train for each class?
if you mean by KNN, k-nearest neighbor, what network that you tested?
KNN cannot be trained, it has no output trained model, for each feature vector to be tested, you need to compare it with all the data in the training set, if the feature vector is about pixels from an image, you need to take all the pixels to be compared with all the training data, this would take a very long time, therefore the KNN classifier is not recommended for segmentation.
so you may use classifier that builds a small model after training such as the ANN, artificial neural networks, you may refer to this work:
or perhaps no need for classifier as John said, you may use clustering such as the k-means clustering algorithm or focus sing on the characteristics of the segmented object, you may refer to this work in this regard: