我似乎在開發光學字符識別引擎時偶然發現了一個小問題。我已經在MNIST圖像上訓練了K最近鄰分類器,並對其進行了測試。它似乎工作正常。但是,當我輸入不同尺寸的圖像時,似乎無法正確分類輸入圖像。 有關如何解決此問題的任何建議?通過比較不同尺寸的圖像來檢測字符
I] KNN分類器 -
爲KNN分類的代碼是:
% herein, I resize the binary image 'b' to contain the
% same dimensions as the training set 'trainingImages' as the input and training Images
% should have the same no. of columns/dimensions
b = imresize(b, size(trainingImages));
% now i try to classify the input image 'b' against the set of training images and
% training labels.
cls = knnclassify(b, trainingImages, trainingLabels, 3, 'euclidean');
CLS現在是分類矢量。但是,無論輸入圖像如何,這幾乎總是顯示1的錯誤分類。
另一方面,當我對MNIST測試圖像進行分類時,得到了非常高的準確性!對於相同的代碼如下 -
class = knnclassify(testImg, trainingImages, trainingLabels, 3, 'euclidean');
現在的主要問題是,不管是什麼樣的輸入圖像的,我給它來預測,它主要是給了我一個錯誤的結果(變化爲不同的圖像),即使是那些截然不同的圖像。似乎它不能正常工作。有人能幫我看看這裏的問題應該在哪裏?我無法從互聯網上的現有資源中找到任何解釋。提前致謝。
如果訓練集trainingImages包含所有模板圖像,那麼您將調整單個圖像b到您的訓練集大小。你應該將b的大小設置爲訓練集中單個字符的大小 – dhanushka
謝謝Dhanushka! 我也是在最後一天晚上得出這個結論的。 – vsdaking