Domanda

I am working on my project on pattern recognition and i am using knn search for finding nearest neighbors, the problem i am facing is that when i get the o/p in ascending order(Rank's) its some sort of array.

x = [v_2;v_3;v_4;v_5]; Training samples

y = v_1; sample image

IDX = knnsearch(x,y,'K',4);

o/p

IDX=[2 3 1 4] final o/p

this shows that my 'sample image' matches to 2nd image first, then to third and so on...

So the question is how can i access these array elemnts. I want to attach images to these elements because i want to display these best matched images.

for ex, in my database i have images stored img1,img2,img3,img4 as the o/p is IDX=[2 3 1 4]

it should show me img2 first,, then img3,, then img1,, at last img4

È stato utile?

Soluzione

First thing you need to do is store all the images in a cell. The 3 images are stored in cell called templates. Then using idx select the image. The code is shown below.Images are shown in top down fashion.

idx = [3 2 1];  output of knn algorithm
len = length(idx);  
templates = {img1,img2,img3}; images stored in cell
for i = 1:len
        num = idx(i);
        subplot(len,1,i);     
        imshow(templates{num},[]);   shows images as per content of idx
end; 

I hope this is what you was searching for...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top