bagofFeatures:Why can't I retrieve similar images using ORB features?

7 次查看(过去 30 天)
As far as I know, bagofFeatures uses the SURF feature detector by default, but after I switched to the custom ORB feature detector, I could not retrieve similar images using the same official sample program, and I tried to adjust some hyperparameters of bagofFeatures, such as "StrongestFeatures" and "TreeProperties" to get more visual words, but still no success. Any good suggestions?
your answer would be greatly appreciate.
%% use https://www.mathworks.com/help/vision/ref/retrieveimages.html first example data
dataDir = fullfile(toolboxdir('vision'),'visiondata','bookCovers');
bookCovers = imageDatastore(dataDir);
queryDir = fullfile(dataDir,'queries',filesep);
queryImage = imread([queryDir 'query3.jpg']);
bof = bagOfFeatures(bookCovers,CustomExtractor=@helperORBFeatureExtractorFunction,StrongestFeatures=0.8,TreeProperties=[3,10]);
Creating Bag-Of-Features. ------------------------- * Extracting features using a custom feature extraction function: helperORBFeatureExtractorFunction. * Extracting features from 58 images...done. Extracted 58000 features. * Keeping 80 percent of the strongest features from each category. * Creating a 1000 word visual vocabulary. * Number of levels: 3 * Branching factor: 10 * Number of clustering steps: 111 * [Step 1/111] Clustering vocabulary level 1. * Number of features : 46400 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.07 seconds/iteration)...converged in 18 iterations. * [Step 2/111] Clustering vocabulary level 2, branch 1. * Number of features : 3626 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 22/100 iterations (~0.01 seconds/iteration)...converged in 22 iterations. * [Step 3/111] Clustering vocabulary level 3, branch 1. * Number of features : 355 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 20/100 iterations (~0.00 seconds/iteration)...converged in 20 iterations. * [Step 4/111] Clustering vocabulary level 3, branch 2. * Number of features : 430 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 5/111] Clustering vocabulary level 3, branch 3. * Number of features : 328 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 6/111] Clustering vocabulary level 3, branch 4. * Number of features : 394 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 23/100 iterations (~0.00 seconds/iteration)...converged in 23 iterations. * [Step 7/111] Clustering vocabulary level 3, branch 5. * Number of features : 354 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 8/111] Clustering vocabulary level 3, branch 6. * Number of features : 319 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 9/111] Clustering vocabulary level 3, branch 7. * Number of features : 299 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 10/111] Clustering vocabulary level 3, branch 8. * Number of features : 383 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 11/111] Clustering vocabulary level 3, branch 9. * Number of features : 397 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 12/111] Clustering vocabulary level 3, branch 10. * Number of features : 367 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 13/111] Clustering vocabulary level 2, branch 2. * Number of features : 5820 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.01 seconds/iteration)...converged in 11 iterations. * [Step 14/111] Clustering vocabulary level 3, branch 1. * Number of features : 790 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 22/100 iterations (~0.00 seconds/iteration)...converged in 22 iterations. * [Step 15/111] Clustering vocabulary level 3, branch 2. * Number of features : 685 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 16/111] Clustering vocabulary level 3, branch 3. * Number of features : 648 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 17/111] Clustering vocabulary level 3, branch 4. * Number of features : 494 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 18/111] Clustering vocabulary level 3, branch 5. * Number of features : 758 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.00 seconds/iteration)...converged in 11 iterations. * [Step 19/111] Clustering vocabulary level 3, branch 6. * Number of features : 366 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 20/111] Clustering vocabulary level 3, branch 7. * Number of features : 570 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 21/111] Clustering vocabulary level 3, branch 8. * Number of features : 453 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 22/111] Clustering vocabulary level 3, branch 9. * Number of features : 550 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 20/100 iterations (~0.00 seconds/iteration)...converged in 20 iterations. * [Step 23/111] Clustering vocabulary level 3, branch 10. * Number of features : 506 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 19/100 iterations (~0.00 seconds/iteration)...converged in 19 iterations. * [Step 24/111] Clustering vocabulary level 2, branch 3. * Number of features : 5573 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.01 seconds/iteration)...converged in 15 iterations. * [Step 25/111] Clustering vocabulary level 3, branch 1. * Number of features : 524 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 26/111] Clustering vocabulary level 3, branch 2. * Number of features : 650 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 28/100 iterations (~0.00 seconds/iteration)...converged in 28 iterations. * [Step 27/111] Clustering vocabulary level 3, branch 3. * Number of features : 671 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 28/111] Clustering vocabulary level 3, branch 4. * Number of features : 734 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 29/111] Clustering vocabulary level 3, branch 5. * Number of features : 437 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.01 seconds/iteration)...converged in 15 iterations. * [Step 30/111] Clustering vocabulary level 3, branch 6. * Number of features : 811 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 31/111] Clustering vocabulary level 3, branch 7. * Number of features : 560 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 32/111] Clustering vocabulary level 3, branch 8. * Number of features : 320 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 33/111] Clustering vocabulary level 3, branch 9. * Number of features : 541 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~0.00 seconds/iteration)...converged in 10 iterations. * [Step 34/111] Clustering vocabulary level 3, branch 10. * Number of features : 325 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~0.00 seconds/iteration)...converged in 10 iterations. * [Step 35/111] Clustering vocabulary level 2, branch 4. * Number of features : 5784 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.02 seconds/iteration)...converged in 13 iterations. * [Step 36/111] Clustering vocabulary level 3, branch 1. * Number of features : 762 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 37/111] Clustering vocabulary level 3, branch 2. * Number of features : 582 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 38/111] Clustering vocabulary level 3, branch 3. * Number of features : 582 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.00 seconds/iteration)...converged in 11 iterations. * [Step 39/111] Clustering vocabulary level 3, branch 4. * Number of features : 665 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 40/111] Clustering vocabulary level 3, branch 5. * Number of features : 642 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 29/100 iterations (~0.00 seconds/iteration)...converged in 29 iterations. * [Step 41/111] Clustering vocabulary level 3, branch 6. * Number of features : 483 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 20/100 iterations (~0.00 seconds/iteration)...converged in 20 iterations. * [Step 42/111] Clustering vocabulary level 3, branch 7. * Number of features : 551 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 43/111] Clustering vocabulary level 3, branch 8. * Number of features : 474 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 22/100 iterations (~0.00 seconds/iteration)...converged in 22 iterations. * [Step 44/111] Clustering vocabulary level 3, branch 9. * Number of features : 714 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 26/100 iterations (~0.00 seconds/iteration)...converged in 26 iterations. * [Step 45/111] Clustering vocabulary level 3, branch 10. * Number of features : 329 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.00 seconds/iteration)...converged in 11 iterations. * [Step 46/111] Clustering vocabulary level 2, branch 5. * Number of features : 4156 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 19/100 iterations (~0.01 seconds/iteration)...converged in 19 iterations. * [Step 47/111] Clustering vocabulary level 3, branch 1. * Number of features : 514 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 48/111] Clustering vocabulary level 3, branch 2. * Number of features : 375 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 49/111] Clustering vocabulary level 3, branch 3. * Number of features : 467 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 50/111] Clustering vocabulary level 3, branch 4. * Number of features : 467 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 51/111] Clustering vocabulary level 3, branch 5. * Number of features : 408 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 52/111] Clustering vocabulary level 3, branch 6. * Number of features : 333 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 53/111] Clustering vocabulary level 3, branch 7. * Number of features : 367 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 54/111] Clustering vocabulary level 3, branch 8. * Number of features : 531 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 55/111] Clustering vocabulary level 3, branch 9. * Number of features : 298 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 56/111] Clustering vocabulary level 3, branch 10. * Number of features : 396 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.01 seconds/iteration)...converged in 12 iterations. * [Step 57/111] Clustering vocabulary level 2, branch 6. * Number of features : 3856 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.01 seconds/iteration)...converged in 13 iterations. * [Step 58/111] Clustering vocabulary level 3, branch 1. * Number of features : 508 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 59/111] Clustering vocabulary level 3, branch 2. * Number of features : 346 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.01 seconds/iteration)...converged in 15 iterations. * [Step 60/111] Clustering vocabulary level 3, branch 3. * Number of features : 263 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 9/100 iterations (~0.00 seconds/iteration)...converged in 9 iterations. * [Step 61/111] Clustering vocabulary level 3, branch 4. * Number of features : 414 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 62/111] Clustering vocabulary level 3, branch 5. * Number of features : 398 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 63/111] Clustering vocabulary level 3, branch 6. * Number of features : 423 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 64/111] Clustering vocabulary level 3, branch 7. * Number of features : 413 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 65/111] Clustering vocabulary level 3, branch 8. * Number of features : 357 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 66/111] Clustering vocabulary level 3, branch 9. * Number of features : 282 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 67/111] Clustering vocabulary level 3, branch 10. * Number of features : 452 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 68/111] Clustering vocabulary level 2, branch 7. * Number of features : 4107 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.01 seconds/iteration)...converged in 15 iterations. * [Step 69/111] Clustering vocabulary level 3, branch 1. * Number of features : 418 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 70/111] Clustering vocabulary level 3, branch 2. * Number of features : 382 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 71/111] Clustering vocabulary level 3, branch 3. * Number of features : 411 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 7/100 iterations (~0.00 seconds/iteration)...converged in 7 iterations. * [Step 72/111] Clustering vocabulary level 3, branch 4. * Number of features : 373 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 73/111] Clustering vocabulary level 3, branch 5. * Number of features : 538 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 12/100 iterations (~0.00 seconds/iteration)...converged in 12 iterations. * [Step 74/111] Clustering vocabulary level 3, branch 6. * Number of features : 421 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 75/111] Clustering vocabulary level 3, branch 7. * Number of features : 421 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 76/111] Clustering vocabulary level 3, branch 8. * Number of features : 389 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 77/111] Clustering vocabulary level 3, branch 9. * Number of features : 323 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 29/100 iterations (~0.00 seconds/iteration)...converged in 29 iterations. * [Step 78/111] Clustering vocabulary level 3, branch 10. * Number of features : 431 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 20/100 iterations (~0.00 seconds/iteration)...converged in 20 iterations. * [Step 79/111] Clustering vocabulary level 2, branch 8. * Number of features : 5378 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 22/100 iterations (~0.01 seconds/iteration)...converged in 22 iterations. * [Step 80/111] Clustering vocabulary level 3, branch 1. * Number of features : 514 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 81/111] Clustering vocabulary level 3, branch 2. * Number of features : 793 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 82/111] Clustering vocabulary level 3, branch 3. * Number of features : 369 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~0.01 seconds/iteration)...converged in 10 iterations. * [Step 83/111] Clustering vocabulary level 3, branch 4. * Number of features : 590 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 22/100 iterations (~0.00 seconds/iteration)...converged in 22 iterations. * [Step 84/111] Clustering vocabulary level 3, branch 5. * Number of features : 356 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 9/100 iterations (~0.00 seconds/iteration)...converged in 9 iterations. * [Step 85/111] Clustering vocabulary level 3, branch 6. * Number of features : 304 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 24/100 iterations (~0.00 seconds/iteration)...converged in 24 iterations. * [Step 86/111] Clustering vocabulary level 3, branch 7. * Number of features : 609 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 87/111] Clustering vocabulary level 3, branch 8. * Number of features : 816 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 88/111] Clustering vocabulary level 3, branch 9. * Number of features : 587 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 15/100 iterations (~0.00 seconds/iteration)...converged in 15 iterations. * [Step 89/111] Clustering vocabulary level 3, branch 10. * Number of features : 440 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~0.00 seconds/iteration)...converged in 10 iterations. * [Step 90/111] Clustering vocabulary level 2, branch 9. * Number of features : 3742 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 26/100 iterations (~0.01 seconds/iteration)...converged in 26 iterations. * [Step 91/111] Clustering vocabulary level 3, branch 1. * Number of features : 391 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 20/100 iterations (~0.00 seconds/iteration)...converged in 20 iterations. * [Step 92/111] Clustering vocabulary level 3, branch 2. * Number of features : 302 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 93/111] Clustering vocabulary level 3, branch 3. * Number of features : 450 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 26/100 iterations (~0.00 seconds/iteration)...converged in 26 iterations. * [Step 94/111] Clustering vocabulary level 3, branch 4. * Number of features : 588 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 23/100 iterations (~0.00 seconds/iteration)...converged in 23 iterations. * [Step 95/111] Clustering vocabulary level 3, branch 5. * Number of features : 296 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 19/100 iterations (~0.00 seconds/iteration)...converged in 19 iterations. * [Step 96/111] Clustering vocabulary level 3, branch 6. * Number of features : 396 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.00 seconds/iteration)...converged in 16 iterations. * [Step 97/111] Clustering vocabulary level 3, branch 7. * Number of features : 253 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 98/111] Clustering vocabulary level 3, branch 8. * Number of features : 406 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 99/111] Clustering vocabulary level 3, branch 9. * Number of features : 343 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 13/100 iterations (~0.00 seconds/iteration)...converged in 13 iterations. * [Step 100/111] Clustering vocabulary level 3, branch 10. * Number of features : 317 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 101/111] Clustering vocabulary level 2, branch 10. * Number of features : 4358 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 19/100 iterations (~0.01 seconds/iteration)...converged in 19 iterations. * [Step 102/111] Clustering vocabulary level 3, branch 1. * Number of features : 591 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.00 seconds/iteration)...converged in 11 iterations. * [Step 103/111] Clustering vocabulary level 3, branch 2. * Number of features : 331 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 16/100 iterations (~0.01 seconds/iteration)...converged in 16 iterations. * [Step 104/111] Clustering vocabulary level 3, branch 3. * Number of features : 403 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 11/100 iterations (~0.00 seconds/iteration)...converged in 11 iterations. * [Step 105/111] Clustering vocabulary level 3, branch 4. * Number of features : 524 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 106/111] Clustering vocabulary level 3, branch 5. * Number of features : 439 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 107/111] Clustering vocabulary level 3, branch 6. * Number of features : 492 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 17/100 iterations (~0.00 seconds/iteration)...converged in 17 iterations. * [Step 108/111] Clustering vocabulary level 3, branch 7. * Number of features : 436 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 14/100 iterations (~0.00 seconds/iteration)...converged in 14 iterations. * [Step 109/111] Clustering vocabulary level 3, branch 8. * Number of features : 417 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 18/100 iterations (~0.00 seconds/iteration)...converged in 18 iterations. * [Step 110/111] Clustering vocabulary level 3, branch 9. * Number of features : 381 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 21/100 iterations (~0.00 seconds/iteration)...converged in 21 iterations. * [Step 111/111] Clustering vocabulary level 3, branch 10. * Number of features : 344 * Number of clusters : 10 * Initializing cluster centers...100.00%. * Clustering...completed 19/100 iterations (~0.00 seconds/iteration)...converged in 19 iterations. * Finished creating Bag-Of-Features
imageIndex2 = invertedImageIndex(bof,SaveFeatureLocations=false);
[feature, featureMetrics]= helperORBFeatureExtractorFunction(queryImage);
addImageFeatures(imageIndex2, feature, 1);
imageIDs2 = retrieveImages(queryImage,imageIndex2)
imageIDs2 = 0×1 empty uint32 column vector
function [features, featureMetrics]= helperORBFeatureExtractorFunction(I)
% helperORBFeatureExtractorFunction Implements the ORB feature extraction
% used in bagOfFeatures.
%
% This is an example helper function that is subject to change or removal
% in future releases.
% Copyright 2021 The MathWorks, Inc.
numPoints = 1000;
% Detect ORB features
Igray = im2gray(I);
points = detectORBFeatures(Igray, 'ScaleFactor', 1.2, 'NumLevels', 8);
% Select a subset of features, uniformly distributed throughout the image
points = selectUniform(points, numPoints, size(Igray, 1:2));
% Extract features
features = extractFeatures(Igray, points);
% Compute the Feature Metric. Use the variance of features as the metric
featureMetrics = var(single(features.Features),[],2);
end

采纳的回答

cui,xingxing
cui,xingxing 2022-12-7
编辑:cui,xingxing 2022-12-8
After I careful thinking, I was lucky enough to find out what the problem was and I am stating the following in the hope that it will help others:
When the bagofFeatures object becomes an input parameter to the invertedImageIndex function, i.e. when constructing an object of the invertedImageIndex class, there are no image features inside the instance of this object to establish a one-to-one correspondence with the image. Before the image retrieval task is performed, i.e. before the retrieveImages function is called, features and the ID number of the corresponding image should be added to each image. This is done by the addImageFeatures object function, which was introduced in R2021b for use in the vSLAM task loop closure detection.
The hyperparameter to the bagOfFeatures function is indeed an empirical adjustment, as described in the documentation.
dataDir = fullfile(toolboxdir('vision'),'visiondata','bookCovers');
bookCovers = imageDatastore(dataDir);
queryDir = fullfile(dataDir,'queries',filesep);
queryImage = imread([queryDir 'query3.jpg']);
bof = bagOfFeatures(bookCovers,CustomExtractor=@helperORBFeatureExtractorFunction,...
StrongestFeatures=1,TreeProperties=[1,500]);% when TreeProperties=[3,10],retrieveImage is not correct,Just an experience value
Creating Bag-Of-Features. ------------------------- * Extracting features using a custom feature extraction function: helperORBFeatureExtractorFunction. * Extracting features from 58 images...done. Extracted 58000 features. * Keeping 100 percent of the strongest features from each category. * Creating a 500 word visual vocabulary. * Number of levels: 1 * Branching factor: 500 * Number of clustering steps: 1 * [Step 1/1] Clustering vocabulary level 1. * Number of features : 58000 * Number of clusters : 500 * Initializing cluster centers...100.00%. * Clustering...completed 26/100 iterations (~0.14 seconds/iteration)...converged in 26 iterations. * Finished creating Bag-Of-Features
imageIndex2 = invertedImageIndex(bof,SaveFeatureLocations=false);
% note: imageIndex2 is empty index,so it should add image feature and image
% id for every canadicate image
for i = 1:length(bookCovers.Files)
currImg = readimage(bookCovers,i);
feature= helperORBFeatureExtractorFunction(currImg);
addImageFeatures(imageIndex2, feature, i);
end
[feature, featureMetrics]= helperORBFeatureExtractorFunction(queryImage);
% addImageFeatures(imageIndex2, feature, i+1);
imageIDs2 = retrieveImages(queryImage,imageIndex2);
if ~isempty(imageIDs2)
simImg = readimage(bookCovers,double(imageIDs2(1)));
figure;imshow(simImg)
end
function [features, featureMetrics]= helperORBFeatureExtractorFunction(I)
% helperORBFeatureExtractorFunction Implements the ORB feature extraction
% used in bagOfFeatures.
%
% This is an example helper function that is subject to change or removal
% in future releases.
% Copyright 2021 The MathWorks, Inc.
numPoints = 1000;
% Detect ORB features
Igray = im2gray(I);
points = detectORBFeatures(Igray, 'ScaleFactor', 1.2, 'NumLevels', 8);
% Select a subset of features, uniformly distributed throughout the image
points = selectUniform(points, numPoints, size(Igray, 1:2));
% Extract features
features = extractFeatures(Igray, points);
% Compute the Feature Metric. Use the variance of features as the metric
featureMetrics = var(single(features.Features),[],2);
end
-----------------------------------------------2022.12.8 update-----------------------------------------------
BTW,The relationship between these functions is indeed a bit confusing, so I drew a class diagram by hand and refer to it below, so please point out any incorrectness!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by