Knn search- after classification how to retrieve the image ? how to find the right value for that index?

92 views Asked by At

i used KNN search for nearest neighbour classification- the size of image is big and i select only 1000 rows-

[EG_Training,idx_GS1]=datasample(enhance1_GS_random,1000);
K=33;
[KNN D]= knnsearch(EG_Training, EG_Testing, 'K',K ,'Distance', 'euclidean');**

EG_Training is 1000 random rows only- now i have a address(index)of each value in KNN and idx_GS1- my question is how to link these indexes in order to have a segmented image for further evaluation- many thanks

2

There are 2 answers

0
Shai On

To get back indices into the original signal enhace1_GS_random, you can

origIdx = idx_GS1( KNN );

BTW, using datasample you get 1000 samples with replacement meaning you might have identical rows in EG_training.

0
Shai On

If you need to convert linear indices into row-column indices you can simply use ind2sub:

[row col] = ind2sub( size(img), ind );